Postgresql 在一个查询中组合不同的排序结果
我应该使用团体还是。。 我尝试了以下查询获得结果:1 2 3Postgresql 在一个查询中组合不同的排序结果,postgresql,Postgresql,我应该使用团体还是。。 我尝试了以下查询获得结果:1 2 3 即使我更改了开始日期asc或结束日期描述也不会发生任何事情 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 更新 我想合并不同的排序结果 SELECT tt
即使我更改了
开始日期asc
或结束日期描述
也不会发生任何事情
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
更新
我想合并不同的排序结果
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
按结束日期asc、开始日期desc、名称asc排序
最后不能使用空值?可以-我想你问的是列顺序如果你想按结束日期asc排序,怎么可能有订单3 1 2?最低结束日期在记录2中,而不是记录3中。你的意思是你想让它们按顺序排列吗?对不起。。。你所问的问题是通过“订单截止日期asc,开始日期desc,名称asc”条款解决的,就像你从一开始就被告知的那样。您可能正在尝试解决另一个问题,您能用文字(而不是sql)来解释它吗?不能最后使用null吗?为什么?这看起来和我的查询一样,为什么不能使用tt.end_date?那么我的查询之间有什么不同呢?我想要排序end_date asc
然后start_date desc
然后name asc
得到结果:3 1 2。你的问题和我之前的问题一样,没什么变化。。。。。。
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)