pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: FatTony <fattony@comcast.net>
To: pgsql-sql@postgresql.org
Subject: order by a "select as" determined by case statement
Date: Fri, 06 Dec 2002 13:05:34 -0500
Message-ID: <000001c29d52$131f4250$1401a8c0@nemesis> (raw)

I'm not a db guru by any means so please forgive me if this has an easy
solution.

Scenario:

Want to sort by an alias for SELECT AGE(). Problem is the timestamps for
the SELECT AGE will be determined by the value of another column, thus
the use of CASE.

What I thought would work.

SELECT tblticket.ticketid,tblstatus.statusname,
CASE WHEN tblstatus.statusname = 'Closed'
THEN (SELECT AGE(tblticket.ticketclosed,tblticket.ticketcreated) as
ticketage)
ELSE (SELECT AGE(CURRENT_TIMESTAMP,tblticket.ticketcreated) as
ticketage) 
END
FROM tblticket CROSS JOIN tblstatus
WHERE (tblticket.reasonid = 2) AND blah, blah, blah
ORDER BY ticketage ASC

CASE apparently completely ignores the ticketage alias. Anyone know how
to get around this?

Thank You.





view thread (2+ messages)  latest in thread

Message-ID: <000001c29d52$131f4250$1401a8c0@nemesis>
Permalink:  ../000001c29d52$131f4250$1401a8c0@nemesis/
Also on:    postgresql.org/message-id/000001c29d52$131f4250$1401a8c0@nemesis

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: fattony@comcast.net
  Subject: Re: order by a "select as" determined by case statement
  In-Reply-To: <000001c29d52$131f4250$1401a8c0@nemesis>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox