mysql - sql query with dynamic headers using case when -


here trying solve (picture @ link) -

  1. how query table, named table1, produce results below it?

transform

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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -