mysql - sql query with dynamic headers using case when -
here trying solve (picture @ link) -
- how query table, named table1, produce results below it?
i stuck on creating dynamic headers. basic jist of i'm @ below.
select case when color = 'blue' count(id) end 'no_of_blue' case when color = 'red' count(id) end 'no_of_red' case when color = 'green' count(id) end 'no_of_green'
select sum(case when color = 'blue' 1 else 0 end) 'no_of_blue', sum(case when color = 'red' 1 else 0 end) 'no_of_red', sum(case when color = 'green' 1 else 0 end) 'no_of_green'
or pivot may useful
Comments
Post a Comment