当前位置: 代码迷 >> Sql Server >> 休息日调询。
  详细解决方案

休息日调询。

热度:112   发布时间:2016-04-27 14:12:20.0
休息日调询。。。在线等。。。
工号 休息日 次数
00010 1,5 2
00013 4,6 2
00016 4,5,6 2
00034 1,2 1
00038 1,6 1
00042 3,4 2
00043 4 1
00049 1,3 2
00058 4 1
00060 2 1
00064 2 1
00065 2 1
00067 4,5,6 3

我想做的就是。。 那天没有休息过,的任一天。星期天除外 结果
00010 6  
00013 5
00016 3
00034 6
00038 5
00042 6
00043 6




------解决方案--------------------
老实说,我没有搞懂。等楼下!
------解决方案--------------------
那你的结果怎么才这么少呢?是这样?
SQL code
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 行受影响)**/
  相关解决方案