以反向计时顺序订购YYYY MM DD [英] Ordering YYYY MM DD in reverse chrono order

查看:59
本文介绍了以反向计时顺序订购YYYY MM DD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试选择不同的日期并按相反的顺序排序

时间顺序。虽然列类型是TIMESTAMP,但是在这个

的情况下,我只想要YYYY,MM和DD。


我使用以下查询,但它我没有按照相反的时间顺序返回日期




SELECT DISTINCT

date_part(''year'' ,uu.add_date),date_part(''month'',uu.add_date),

date_part(''day'',uu.add_date)


来自uus INNER JOIN ui ON uus.user_id = ui.id INNER JOIN uu ON

ui.id = uu.user_id

WHERE uus.x_id = 1


ORDER BY

date_part(''year'',uu.add_date),date_part(''month'',uu.add_date),

date_part(''day'',uu.add_date)DESC;

这就是上面的查询返回的内容:


date_part | date_part | date_part

----------- + ----------- + -----------

2004 | 2 | 6

2004 | 4 | 20

(2行)

我想回到这样的东西:

2004 4 20

2004 4 19

2004 2 6

....


我的查询显然是错误的,但我不能看到错误。我是b / b
想知道是否有其他人可以看到它。只是将DESC更改为ASC,

无效。


谢谢!

解决方案

----- BEGIN PGP签名消息-----

哈希:SHA1

ORDER BY
date_part(' 'year'',uu.add_date),date_part(''month'',uu.add_date),
date_part(''day'',uu.add_date)DESC;




您按三列排序,只有最后一列是desc。


你需要的是:


....

订购

date_part(''year'',uu.add_date)desc,

date_part(''month'',uu.add_date)desc,

date_part(''day '',uu.add_date)desc

;


Mit freundlichem Gru? /亲切的问候

Holger Klawitter

- -

列出< at> klawitter< dot> de $ / $
-----开始PGP SIGNATURE -----

版本:GnuPG v1.2.2(GNU / Linux)


iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k / dmmwCfa7gB

cUjzCy / X0mJXW0Aooyb7pbE =

= 0Fhk

----- END PGP SIGNATURE -----

---------------------------(广播结束)---------- -----------------

提示8:解释分析是你的朋友


< blockquote> ----- BEGIN PGP签名消息-----

哈希:SHA1

ORDER BY
date_part(''year '',uu.add_date),date_part(''month'',uu.add_date),
date_part(''day'',uu.add_date)DESC;



您按三列排序,只有最后一列是desc。


你需要的是:


....

订购

date_part(''year'',uu.add_date)desc,

date_part(''month'',uu.add_date)desc,

date_part(''day '',uu.add_date)desc

;


Mit freundlichem Gru? /亲切的问候

Holger Klawitter

- -

列出< at> klawitter< dot> de $ / $
-----开始PGP SIGNATURE -----

版本:GnuPG v1.2.2(GNU / Linux)


iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k / dmmwCfa7gB

cUjzCy / X0mJXW0Aooyb7pbE =

= 0Fhk

----- END PGP SIGNATURE -----

---------------------------(广播结束)---------- -----------------

提示8:解释分析是你的朋友


< blockquote>你有没有尝试


ORDER BY

date_part(''year'',uu.add_date)desc,date_part(''month'',uu .add_date)desc,

date_part(''day'',uu.add_date)DESC;


问候,

Clodoaldo

--- OtisUsenet< ot ********* @ yahoo.com> escreveu:>您好,


我正在尝试选择不同的日期并按相反的顺序排列它们。虽然列类型是TIMESTAMP,但在这种情况下我只想要YYYY,MM和DD。

我正在使用以下查询,但它不会返回日期
反向时间顺序:

SELECT DISTINCT
date_part(''year'',uu.add_date),date_part(''month'',uu.add_date),
date_part(''day'',uu.add_date)

来自uus INNER JOIN ui ON uus.user_id = ui.id INNER JOIN uu ON
ui.id = uu。 user_id
在哪里uus.x_id = 1

order BY
date_part(''year'',uu.add_date),date_part(''month'',uu.add_date) ,
date_part(''day'',uu.add_date)DESC;

这就是上面的查询返回的内容:

date_part | date_part | date_part
----------- + ----------- + -----------
2004 | 2 | 6
2004 | 4 | 20
(2行)

我想回到这样的事情:
2004 4 20
2004 4 19
2004 2 6 br /> ...

我的查询显然是错误的,但我看不出错误。我想知道是否有其他人可以看到它。只是将DESC改为ASC,确实没有用。

谢谢!

----------------- ----------(广播结束)---------------------------
提示6:有您搜索了我们的列表档案?

http://archives.postgresql.org




__________________________________________________ ____________________


Yahoo! Messenger - Fale com seus amigos online。 Instale agora!
http://br.download.yahoo.com/信使/


---------------------------(播出结束) ---------------------------

提示8:解释分析是你的朋友

Hello,

I am trying to select distinct dates and order them in the reverse
chronological order. Although the column type is TIMESTAMP, in this
case I want only YYYY, MM, and DD back.

I am using the following query, but it''s not returning dates back in
the reverse chronological order:

SELECT DISTINCT
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date)

FROM uus INNER JOIN ui ON uus.user_id=ui.id INNER JOIN uu ON
ui.id=uu.user_id
WHERE uus.x_id=1

ORDER BY
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date) DESC;
This is what the above query returns:

date_part | date_part | date_part
-----------+-----------+-----------
2004 | 2 | 6
2004 | 4 | 20
(2 rows)
I am trying to get back something like this:
2004 4 20
2004 4 19
2004 2 6
....

My query is obviously wrong, but I can''t see the mistake. I was
wondering if anyone else can see it. Just changing DESC to ASC, did
not work.

Thank you!

解决方案

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ORDER BY
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date) DESC;



You are sorting by three columns, only the last one is desc.

What you need is:

....
order by
date_part( ''year'', uu.add_date ) desc,
date_part( ''month'', uu.add_date ) desc,
date_part( ''day'', uu.add_date ) desc
;

Mit freundlichem Gru? / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k/dmmwCfa7gB
cUjzCy/X0mJXW0Aooyb7pbE=
=0Fhk
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ORDER BY
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date) DESC;



You are sorting by three columns, only the last one is desc.

What you need is:

....
order by
date_part( ''year'', uu.add_date ) desc,
date_part( ''month'', uu.add_date ) desc,
date_part( ''day'', uu.add_date ) desc
;

Mit freundlichem Gru? / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k/dmmwCfa7gB
cUjzCy/X0mJXW0Aooyb7pbE=
=0Fhk
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Did you try

ORDER BY
date_part(''year'', uu.add_date) desc, date_part(''month'', uu.add_date) desc,
date_part(''day'', uu.add_date) DESC;

Regards,
Clodoaldo
--- OtisUsenet <ot*********@yahoo.com> escreveu: > Hello,


I am trying to select distinct dates and order them in the reverse
chronological order. Although the column type is TIMESTAMP, in this
case I want only YYYY, MM, and DD back.

I am using the following query, but it''s not returning dates back in
the reverse chronological order:

SELECT DISTINCT
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date)

FROM uus INNER JOIN ui ON uus.user_id=ui.id INNER JOIN uu ON
ui.id=uu.user_id
WHERE uus.x_id=1

ORDER BY
date_part(''year'', uu.add_date), date_part(''month'', uu.add_date),
date_part(''day'', uu.add_date) DESC;
This is what the above query returns:

date_part | date_part | date_part
-----------+-----------+-----------
2004 | 2 | 6
2004 | 4 | 20
(2 rows)
I am trying to get back something like this:
2004 4 20
2004 4 19
2004 2 6
...

My query is obviously wrong, but I can''t see the mistake. I was
wondering if anyone else can see it. Just changing DESC to ASC, did
not work.

Thank you!

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



__________________________________________________ ____________________

Yahoo! Messenger - Fale com seus amigos online. Instale agora!
http://br.download.yahoo.com/messenger/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


这篇关于以反向计时顺序订购YYYY MM DD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆