休息日调询。。。在线等。。。
工号 休息日 次数
000101,52
000134,62
000164,5,62
000341,21
000381,61
000423,42
0004341
000491,32
0005841
0006021
0006421
0006521
000674,5,63
我想做的就是。。 那天没有休息过,的任一天。星期天除外 结果
00010 6
00013 5
00016 3
00034 6
00038 5
00042 6
00043 6
[解决办法]
老实说,我没有搞懂。等楼下!
[解决办法]
那你的结果怎么才这么少呢?是这样?
if object_id('[tb]') is not null drop table [tb]gocreate table [tb]([工号] varchar(5),[休息日] varchar(5),[次数] int)insert [tb]select '00010','1,5',2 union allselect '00013','4,6',2 union allselect '00016','4,5,6',2 union allselect '00034','1,2',1 union allselect '00038','1,6',1 union allselect '00042','3,4',2 union allselect '00043','4',1 union allselect '00049','1,3',2 union allselect '00058','4',1 union allselect '00060','2',1 union allselect '00064','2',1 union allselect '00065','2',1 union allselect '00067','4,5,6',3go;with t1 as(select a.工号,b.wkfrom tb ajoin ( select 1 as wk union select 2 union select 3 union select 4 union select 5 union select 6) bon charindex(ltrim(wk),休息日)=0)select * from t1 twhere wk=(select top 1 wk from t1 where 工号=t.工号 order by wk desc)/**工号 wk----- -----------00010 600013 500016 300034 600038 500042 600043 600049 600058 600060 600064 600065 600067 3(13 行受影响)**/