读书人

sql语句先不明白呢挺简单的应该

发布时间: 2013-06-25 23:45:41 作者: rapoo

求一个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
[解决办法]
楼上正解……
[解决办法]
引用:
Quote: 引用:

SELECT  * 
FROM a
ORDER BY acttime DESC,index DESC


引用:
select * from a


order by acttime desc,index desc




我试过,这样是不好使的。 你们可以多建几条数据看

举例说明那里不好使了

读书人网 >SQL Server

热点推荐