sql - Count of Type using if then else -


I have this table in which I have to count 1 as type = D , but if it ends with RR, then it should be calculated as 0 . If ID 123 always starts with D, then R 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 SQL is written after sum (if (type = d) is 1 and 0 end) . I am getting the correct code, unless the code is the type / position and this is the only id in DB that ends with the position R and does not run in D. I need help writing sql

Thanks for the help in advance.

If you are interested in all records type D and R. You must somehow mark the previous record. It can be ranked with rank rank 1 for latest entry.

Then group by ID and see if there is a final record with type R for that ID. If this happens then the result is 0, and then count type D. Select the ID

 , when the maximum case (case when last_is_one = 1 and type = 'r' then 1 end) = 1 then 0 and calculation ('d', 'r') Type) since the 'mytable' as the last_s_on (when type = 'D' then 1 ends) is in the form of d_count (select id, type, rank ()) ID by d_and_r group ;  

SQL Belal :.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -