sql - Multiple Selects (with Null) from the same table -


so have write sql in db2, , cant figure out how it. pick these field codes , values finance table long above $10,000

select  (a.value), (b.value), (c.value)  ...   client  k, finance a, finance b, finance c ... 

the problem in statement. cannot put:

where k.client  = a.client , a.fieldcode = 1 , a.value > 10000 , k.client  = b.client , b.fieldcode = 2 , b.value > 10000 ... 

and on... because doesnt include nulls, drastically reduces result set, more times call finance table.

how keep above formatting , include nulls display line long either finance or finance b or finance c etc exists?

(note: doing first obvious thing repeatedly calling finance table once, finance a, no b,c,d etc not work problem because results (from a,b,c,d etc) cannot spaced out on many lines).

this compressed version of doing:

select    a.client_id,   a.period_id,   fn0.amount,   fn2.amount assesment left outer join finance fn0      on a.client_id = fn0.client_id     , a.period_id = fn0.period_id left outer join finance fn1      on a.client_id = fn1.client_id     , a.period_id = fn1.period_id   fn0.fld_cd  = 1258860  , fn1.fld_cd = 1258861 

the problem im still having is, if blank out fn1 related lines, lot more returned values. aka still not including null values, , returning values if field codes have values.

you need left outer join instead of comma separated inner join

select a.value,        b.value,        c.value   client k        left join finance               on k.client = a.client                  , a.value > 10000                  , a.fieldcode = 1        left join finance b               on k.client = b.client                  , b.value > 10000                  , b.fieldcode = 2        left join finance c               on k.client = c.client                   ...... 

update :

move left table filters on condition else implicitly converted inner join. try this

select a.client_id,         a.period_id,         fn0.amount,         fn2.amount    assesment         left outer join finance fn0                      on a.client_id = fn0.client_id                         , a.period_id = fn0.period_id                         , fn0.fld_cd = 1258860         left outer join finance fn1                      on a.client_id = fn1.client_id                         , a.period_id = fn1.period_id                         , fn1.fld_cd = 1258861  

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -