Re: CASE in ORDER BY clause
От
Viatcheslav Kalinin
Тема
Re: CASE in ORDER BY clause
Дата
Msg-id
468E66CA.8090208@ipcb.net
Ответ на
CASE in ORDER BY clause (Louis-David Mitterrand)
Список
Дерево обсуждения
CASE in ORDER BY clause Louis-David Mitterrand <vindex+lists-pgsql-general@apartia.org>
Re: CASE in ORDER BY clause Viatcheslav Kalinin <vka@ipcb.net>
Re: CASE in ORDER BY clause Viatcheslav Kalinin <vka@ipcb.net>
Re: CASE in ORDER BY clause Louis-David Mitterrand <vindex+lists-pgsql-general@apartia.org>
Re: CASE in ORDER BY clause Louis-David Mitterrand <vindex+lists-pgsql-general@apartia.org>
Re: CASE in ORDER BY clause Gregory Stark <stark@enterprisedb.com>
Re: CASE in ORDER BY clause Perry Smith <pedz@easesoftware.com>
Re: CASE in ORDER BY clause Martijn van Oosterhout <kleptog@svana.org>
Re: CASE in ORDER BY clause Tom Lane <tgl@sss.pgh.pa.us>
Re: CASE in ORDER BY clause Perry Smith <pedz@easesoftware.com>
Re: CASE in ORDER BY clause Lew <lew@lewscanon.nospam>
Re: CASE in ORDER BY clause "Uwe C. Schroeder" <uwe@oss4u.com>
Re: CASE in ORDER BY clause Tom Allison <tom@tacocat.net>
Louis-David Mitterrand wrote: > Hi, > > I am trying the following: > > critik=# select start_date from show_date order by case when start_date > CURRENT_DATE then start_date desc else start_date asc end; > ERROR: syntax error at or near "desc" > LINE 1: ...se when start_date > CURRENT_DATE then start_date desc else > ... > > If I remove the "desc" and "asc" then the quey is accepted but doesn't > do what I want. > > OTOH if I try: > > critik=# select start_date from show_date order by start_date case when start_date > CURRENT_DATE then desc else asc end; > ERROR: syntax error at or near "case" > LINE 1: ...ect start_date from show_date order by start_date case when ... > > How can i order ASC or DESC depending on a condition? > > Thanks, > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > Try this: # select start_date from show_date # order by # case when start_date > CURRENT_DATE then start_date end desc, # when start_date <= CURRENT_DATE then start_date end asc;
В списке pgsql-general по дате отправления