Reputation: 115
get the count value from the table given below
there is a table1 values and i given output .How to i get the output i need php mysql code for this output.
table1
sorry guys i dont know how to create table.just i created. the table contains 3 rows
space represent as ####.
id #### product #### reactions
------------------------
1. axe #### bad
2. colgate #### good
3. axe #### normal
4. axe #### good
5. axe #### bad
6. colgate #### good
7. axe #### bad
8. axe #### normal
9. axe #### good
10. colgate #### bad
ouput
id #### product #### good #### bad #### normal ##
1. axe #### 2 #### 3 #### 2
2. colgate #### 2 #### 1 #### 0
Upvotes: 1
Views: 67
Reputation: 360602
SELECT id, product, SUM(reactions = 'bad') AS bad, SUM(reactions = 'good') AS good,
SUM(reactions = 'normal') AS normal
FROM yourtable
GROUP BY product
Upvotes: 1