On 12/08/2017 05:41, Michael Moore wrote:
with x as
(select id,1 mark from my_table where cat = 3
union all
select null,0 mark)
select id from x where mark = (select max(mark) from x) alia;
Don't have SQL right now so can't test it.
I liked this!
Also an array solution, since it was mentioned, first an existing example, then a non-existing :
smadev dynacom=# select unnest(CASE WHEN arr='{}' THEN '{null}' ELSE arr END) FROM (select ARRAY(select id from flags where id=221) as arr) qry;
unnest
--------
221
(1 row)
smadev dynacom=#
smadev dynacom=# select unnest(CASE WHEN arr='{}' THEN '{null}' ELSE arr END) FROM (select ARRAY(select id from flags where id=-221) as arr) qry;
unnest
--------
(1 row)
smadev dynacom=#
--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt