日期:2014-05-17 浏览次数:20842 次
create table tb# (id int not null, zhuti varchar(10), riqi datetime) insert into tb#(id, zhuti ,riqi) select 1, '大家好','2012-1-3' union all select 2,'大',' 2012-1-5' union all select 3 , '家 ','2012-1-5' union all select 4 , '好 ','2012-1-10' union all select 5 , '欢迎','2012-1-10' union all select 6 , '光临 ','2012-1-10' select * from tb# select zhuti from( select distinct cast(year(riqi) as varchar(4))+' - '+ cast(month(riqi) as varchar(2))+' - '+ cast(day(riqi) as varchar(2)) as zhuti,riqi from tb# union all select zhuti,riqi from tb# ) as a order by riqi desc,zhuti --结果 /* 2012 - 1 - 10 光临 好 欢迎 2012 - 1 - 5 大 家 2012 - 1 - 3 大家好 */