I have a query in PostgreSQL
which returns:
id operation quantity date
----------------------------------------
1282 WITHDRAW 20 2015-01-01
541 INCOMING 50 2015-01-01
4788 ACCEPT 17 2015-01-01
4789 ACCEPT 20 2015-01-01
.....
The query order sort the records by date
...
However, I want to do a secondary order by operation
: first INCOMING
, then ACCEPT
, then WITHDRAW
. Order between records of the same operation is not important:
541 INCOMING 50 2015-01-01
4788 ACCEPT 17 2015-01-01
4789 ACCEPT 20 2015-01-01
1282 WITHDRAW 20 2015-01-01
or
541 INCOMING 50 2015-01-01
4789 ACCEPT 20 2015-01-01
4788 ACCEPT 17 2015-01-01
1282 WITHDRAW 20 2015-01-01
both ok.
I can not use the operation
column nor the id
column because it won't give the desired result...
Select ...
from ...
where ...
order by date
How can I manually specify the order I want..?
I'm looking for SQL syntax for something like:
order by date, (operation order by: INCOMING,ACCEPT,WITHDRAW)