sql语句,先不明白呢,挺简单的应该
求一个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
------解决方案--------------------
------解决方案--------------------
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.000 7号 1
2013-06-07 00:00:00.000 8号 0
2013-06-06 00:00:00.000 5号 1
2013-06-06 00:00:00.000 6号 0
2013-06-05 00:00:00.000 3号 1
2013-06-05 00:00:00.000 4号 0
2013-06-04 00:00:00.000 2号 1
2013-06-04 00:00:00.000 1号 0
证明没有问题
------解决方案--------------------
index是关键字,改成index1了
------解决方案--------------------
order by acttime desc,index desc
------解决方案--------------------
select * from a order by acttime desc,[index] desc
------解决方案--------------------
楼上正解……
------解决方案--------------------
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.000 7号 1
2013-06-07 00:00:00.000 8号 0
2013-06-06 00:00:00.000 5号 1
2013-06-06 00:00:00.000 6号 0
2013-06-05 00:00:00.000 3号 1
2013-06-05 00:00:00.000 4号 0
2013-06-04 00:00:00.000 2号 1
2013-06-04 00:00:00.000 1号 0
证明没有问题
------解决方案--------------------
index是关键字,改成index1了
------解决方案--------------------
order by acttime desc,index desc
------解决方案--------------------
select * from a order by acttime desc,[index] desc
------解决方案--------------------
楼上正解……
------解决方案--------------------