database - "if, then, else" in SQLite -
without using custom functions, possible in sqlite following. have 2 tables, linked via common id numbers. in second table, there 2 variables. able return list of results, consisting of: row id, , null if instances of 2 variables (and there may more two) null, 1 if 0 , 2 if 1 or more 1.
what have right follows:
select a.aid, (select count(*) w3s19 b a.aid=b.aid) num, (select count(*) w3s19 c a.aid=c.aid , h110 null , h112 null) num_null, (select count(*) w3s19 d a.aid=d.aid , (h110=1 or h112=1)) num_yes w3
so requires step through each result follows (rough python pseudocode):
if row['num_yes'] > 0: out[aid] = 2 elif row['num_null'] == row['num']: out[aid] = 'null' else: out[aid] = 1
is there easier way? thanks!
use case...when
, e.g.
case x when w1 r1 when w2 r2 else r3 end
read more sqlite syntax manual (go section "the case expression").
Comments
Post a Comment