postgresql - Show the count based on some condition -


i've asked question days back. here link. count() corresponding max()

now same set of tables (sql fiddle) check different condition

if first question count related max of status, question showing count based on next status of every project.

explanation

as can see in table user_approval,appr_prjt_id=1 has 3 different statuses namely 10,20 ,30. , next status 40 (with every approval status increased 10) , on. possible show there project status waiting 40? count must shown status corresponding 40 in output (not in statuses 10,20,30,...etc)

desired output:

              10   |    20  |  30   |   40  location1     0    |    0   |   0   |   1 

not sure the next status 40 means. assuming status increased 10 every approval, following should work:

select *  user_projects pr exists (   select * user_approval ex   ex.appr_prjt_id = pr.proj_id   , ex.appr_status = 30   ) , not exists (   select * user_approval nx   nx.appr_prjt_id = pr.proj_id   , nx.appr_status >= 40   ); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -