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
Post a Comment