求一个sql语句,先不明白呢,挺简单的应该
A表
actTime title index
2013-06-04 1号 0
2013-06-04 2号 1
2013-06-05 3号 1
2013-06-05 4号 0
actTime:时间类型
title:标题
index:排序字段(1的靠前)
我的需求是查询的数据是按照actTime和index共同排序,即降序的每一天中index为1的靠前.
查询出来如下
actTime title index
2013-06-05 3号 1
2013-06-05 4号 0
2013-06-04 2号 1
2013-06-04 1号 0
[解决办法]
select * from a
order by acttime desc,index desc
[解决办法]
SELECT *
FROM a
ORDER BY acttime DESC,index DESC
[解决办法]
create table haohao(
actTime datetime,
title varchar(255),
index1 varchar(255)
)
insert into haohao
select
'2013-06-04' , '1号', '0' union all
select
'2013-06-04' , '2号', '1' union all
select
'2013-06-05' , '3号', '1' union all
select
'2013-06-05' , '4号', '0' union all
select
'2013-06-06' , '5号', '1' union all
select
'2013-06-06' , '6号', '0' union all
select
'2013-06-07' , '7号', '1' union all
select
'2013-06-07' , '8号', '0'
select * from haohao order by acttime desc,index1 desc
结果
2013-06-07 00:00:00.0007号1
2013-06-07 00:00:00.0008号0
2013-06-06 00:00:00.0005号1
2013-06-06 00:00:00.0006号0
2013-06-05 00:00:00.0003号1
2013-06-05 00:00:00.0004号0
2013-06-04 00:00:00.0002号1
2013-06-04 00:00:00.0001号0
证明没有问题
[解决办法]
index是关键字,改成index1了
[解决办法]
order by acttime desc,index desc
[解决办法]
select * from a order by acttime desc,[index] desc
[解决办法]
楼上正解……
[解决办法]
举例说明那里不好使了