读书人

小弟我有一张表请教怎么按某字段来排

发布时间: 2012-01-14 20:02:35 作者: rapoo

我有一张表,请问如何按某字段来排序?
例如有表 table aaa

字段为id title content type

表中的type有两种情况,会员、非会员。我如何让所有会员信息按时间顺序排在非会员后头?

会员 2007-3-13
会员 2007-3-12
会员 2007-3-12
会员 2007-3-11
会员 2007-3-10
非会员 2007-3-13
非会员 2007-3-11
非会员 2007-3-11
非会员 2007-3-11

[解决办法]
order by type desc
[解决办法]
select * from tb where type = '非会员 ' order by 时间
union all
select * from tb where type = '会员 ' order by 时间

[解决办法]
直接order by不就好了吗?只不过把会员类型放前,日期放后……
反正会员类型就2个,不是asc就素desc
[解决办法]
Select * From aaa Order By (Case type When N '会员 ' Then 0 Else 1 End), 时间字段

读书人网 >SQL Server

热点推荐