sql - Query to Count values from different columns -
i looking query can work in access gives me total count of users completed requirements. know can group column, "tricky" part need group in 1 column if user completed of requirements columns b,c or d. in other words, data:
user company b c d e john abc 1 1 bob abc 1 1 1 1 reggie abc 1 1 1 alex bca 1 mary bca 1 1 jane cba 1 1 1 1
and end result i'm looking:
company e f(b or c or d) abc 2 3 2 bca 2 0 1 cba 1 0 1
you can use nz (coalesce in sql) make null values 0 can "normal" work -- adding them in example:
select sum(nz(b,0)+nz(c,0)+nz(d,0)) f
or looking @ logic
select sum(iif(nz(b,0)+nz(c,0)+nz(d,0) > 0,1,0) ) f
(nb, case when end used instead if iif in sql)
Comments
Post a Comment