SQL - operate on current condition row -


i'd illustrate question using free sql 'simulator': http://sqlzoo.net/wiki/select_from_nobel_tutorial

assume please given list of subject/winner pairs (i put them in where..or clauses) , want them listed in result additional flag 'is in db?' y/n.

i tried prepare sth like:

select subject, winner,  ( case    when winner null 'n'   else 'y' ) "is in db?"  nobel  (subject='literature' , winner='saint-john perse') or (subject='medicine' , winner='sir frank macfarlane burnet') or (subject='medicine' , winner='peter medawar') or (subject='medicine' , winner='christiano ronaldo') 

only last or condition won't give result. despite listed flag n, otherwise wouldn't put case sentence existing rows.

not sure either if case sentence correct @ all. tried

case winner when null 'n' 

possibly select in select or temporary table? kindly advise

you didn't specify dbms ansi sql:

with check_data (subject, winner) (    values       ('literature', 'saint-john perse'),       ('medicine', 'sir frank macfarlane burnet'),      ('medicine', 'peter medawar'),      ('medicine', 'christiano ronaldo') )  select cd.subject,         cd.winner,         case         when           winner null 'n'          else 'y'        end "is in db?"  check_data cd.   left join nobel n       on n.subject = cd.subject       , n.winner = cd.winner 

not dbms support "anonymous" row-constructor using values though. might need dummy select in common table expression.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -