tasktime
id | name | start_date | end_date ...
1 | a | 2016-12-22 | 2017-01-01
2 | b | 2016-05-01 | 2016-05-31
3 | c | 2016-06-01 | 2016-12-25
我应该使用组还是..
我试过以下查询得到的结果:1 2 3
即使我改变了start_date asc
或end_date desc
也没有发生,
SELECT
tt.*
FROM tasktime tt
ORDER BY tt.name asc NULLS LAST
, tt.start_date desc NULLS LAST
, tt.end_date asc NULLS LAST
更新
我希望结合不同的排序结果
SELECT
tt.*
FROM tasktime tt
ORDER BY tt.end_date asc NULLS LAST
then use above result
ORDER BY tt.start_date desc NULLS LAST
then use above result
ORDER BY tt.name asc NULLS LAST
请关闭这个问题......我意识到自己想要什么,这个问题是完全错误的
答案 0 :(得分:0)
喜欢这里?
t=# create table tasktime (id int, name text, start_date date, end_date date);
CREATE TABLE
t=# insert into tasktime values (1,'a','2016-12-22', '2017-01-01'), (2, 'b', '2016-05-01', '2016-05-31'), (3, 'c', '2016-06-01','2016-12-25');
INSERT 0 3
t=# SELECT
t-# tt.*
t-# FROM tasktime tt
t-# order by tt.end_date asc NULLS LAST
t-# , tt.start_date desc NULLS LAST
t-# , tt.name asc NULLS LAST;
id | name | start_date | end_date
----+------+------------+------------
2 | b | 2016-05-01 | 2016-05-31
3 | c | 2016-06-01 | 2016-12-25
1 | a | 2016-12-22 | 2017-01-01
(3 rows)