jeudi 22 janvier 2015

Count of Type using if then else

I have this following table in which i need to count type=D as 1, but if that ID ends with R then it should count as 0. ID 123 always starts with D then it can be R then can be D or A.



ID Decision Dt Type/Status
123 1/15/2014 D
123 1/20/2014 A
123 1/15/2014 R


i have written SQL as sum(if(type=d)then 1 else 0 end). I am getting the right count until type/status is R. And this is the only ID in DB which ends with status R and not moved to D. I need help in writing the sql. Thanks for the help in advance.


Aucun commentaire:

Enregistrer un commentaire