本文介绍了我如何从表中获取周计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从表中选择了我的记录,我希望按工作日订购,例如
在第一张唱片中
星期六
星期日
...
..
我的代码如下:
周是tb1中的字段。
从tb1中选择*其中Scode ='123'按周排序
i selected my records from table i want to order it by week days for example
in first record
saturday
sunday
...
..
my code is in below:
week is field in tb1.
select *from tb1 where Scode='123' order by week
推荐答案
--setup test data
declare @tab table(id int identity(1,1), week nvarchar(50));
insert into @tab
select N'sunday' week
union all select N'saturday' week
union all select N'monday' week
union all select N'friday' week
union all select N'wednesday' week
union all select N'tuesday' week
union all select N'wednesday' week
union all select N'saturday' week
union all select N'thursday' week
union all select N'sunday' week
;
--query order by case
select *
from @tab
order by
case lower(week)
when 'saturday' then 0
when 'sunday' then 1
when 'monday' then 2
when 'tuesday' then 3
when 'wednesday' then 4
when 'thursday' then 5
when 'friday' then 6
end
;
--modify the case statements to get the desired order of the week
如果可能,请参考Tomas Takac关于按日期排序的建议(上面的评论)。
Take Tomas Takac suggestion (comment above) about order by date if possible.
这篇关于我如何从表中获取周计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!