现在我有一张表,想对他的时间字段和季节排序,例如在秋天的时候要把春天和秋天的衣服排在前面,夏天的衣服排在后面,
下面是这张表:
product_ID product_addtime season
1 2010-04-07 1,3
2 2010-04-06 2
3 2010-01-31 1
4 2010-04-20 3
我想要的结果是:
product_ID product_addtime season
4 2010-04-20 3
1 2010-04-07 1,3
3 2010-01-31 1
2 2010-04-06 21 代表春,2代表 夏 3代表 秋
下面是这张表:
product_ID product_addtime season
1 2010-04-07 1,3
2 2010-04-06 2
3 2010-01-31 1
4 2010-04-20 3
我想要的结果是:
product_ID product_addtime season
4 2010-04-20 3
1 2010-04-07 1,3
3 2010-01-31 1
2 2010-04-06 21 代表春,2代表 夏 3代表 秋
解决方案 »
- 谁有日月年联动下拉框啊
- Gridview如何根据数据项的值改变颜色?
- ajax 问题
- url 重写
- DataGrid帮我解决这个问题,急急!!!
- 在一个自定义的类中怎么引用System.Web.HttpContext?
- 新闻采集,实际上就是用 正则表达式 从别人的网站提取 HTML 数据 ???
- 请用过Haokoo.net(c#) 全站程序的大侠进来看看!
- 散分:俺的asp.net要改写成asp了
- asp.net中没有装SQL SERVER 2000可不可以用sql server啊?asp.net中是不是自带了sql server?
- DataSet 更新 数据库中表的问题
- .net一个查询的问题谁能帮帮我
from table
order by
IIF(IIF(charindex(season,'1')>0,
0, IIF(charindex(season,'3')>0, 1, 2) ASC
alter table a add s intupdate a set s = '0' where season = '3' and month(getdate()) in (9,10,11)
update a set s = '1' where season = '1,3' and month(getdate()) in (9,10,11)
update a set s = '2' where season = '1' and month(getdate()) in (9,10,11)
update a set s = '3' where season = '2' and month(getdate()) in (9,10,11)select * from a order by s asc , product_addtime desc
a是表名,month(getdate()) in (9,10,11) 代表秋天的时候随便写的,LZ参考下
from table
order by
IIF(charindex(season,'1')>0, 0, IIF(charindex(season,'3')>0, 1, 2)),
product_addtime
' 排序字段'=Cast season When '秋天' Then 100
When '夏天' Then 1
From a
Order By 排序字段
;with tbl as (select (Case WHEN season='3' THEN 1 WHEN season='1,3' THEN 2 WHEN season='1' THEN 3 ELSE 4 END) AS lv from '表'
)
SELECT * FROM tbl order by lv ASC