I need to write a SQL query which can fetch data and can b exported in XL sheet -


i need write sql query can fetch data , can b exported in xl sheet.

scenario

there 2 tables , b. b child of , there 1 many relation (means b can have many children of a). b has column c can have 2 values 1 or 2.

requirement

i need show in report - each record of table a, count of "number of child records having value 1 in column c of table b", count of "number of child records having value 2 in column c of table b" , count "total number of child records in column c".

something perhaps:

select a.pk,        sum(case when b.c = 1 1 else 0 end) totalc1,        sum(case when b.c = 2 1 else 0 end) totalc2,        count(b.c) totalchildren             inner join b             on a.pk = b.fk_to_a     group a.pk 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -