Hello, I am trying to select distinct dates and order them in the reversechronological order. Although the column type is TIMESTAMP, in thiscase I want only YYYY, MM, and DD back. I am using the following query, but it''s not returning dates back inthe reverse chronological order: SELECT DISTINCTdate_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 ONui.id=uu.user_idWHERE uus.x_id=1 ORDER BYdate_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 | 62004 | 4 | 20(2 rows)I am trying to get back something like this:2004 4 202004 4 192004 2 6.... My query is obviously wrong, but I can''t see the mistake. I waswondering if anyone else can see it. Just changing DESC to ASC, didnot work. Thank you! 解决方案 You are sorting by three columns, only the last one is desc. What you need is: ....order bydate_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 regardsHolger Klawitter- --lists <at> klawitter <dot> de-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k/dmmwCfa7gBcUjzCy/X0mJXW0Aooyb7pbE==0Fhk-----END PGP SIGNATURE--------------------------------(end of broadcast)---------------------------TIP 8: explain analyze is your friend You are sorting by three columns, only the last one is desc. What you need is: ....order bydate_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 regardsHolger Klawitter- --lists <at> klawitter <dot> de-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFAjTtF1Xdt0HKSwgYRAmaDAKCcSo5kEPkn4QJfsFhg9E E0k/dmmwCfa7gBcUjzCy/X0mJXW0Aooyb7pbE==0Fhk-----END PGP SIGNATURE--------------------------------(end of broadcast)---------------------------TIP 8: explain analyze is your friend __________________________________________________ ____________________ 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 21:58