从下表中获取计数值
有一个表 1 的值,我给出了输出。我如何获得输出 我需要此输出的 php mysql 代码。
表1
抱歉,我不知道如何创建表格。只是我创建的。 该表包含 3 行
空格表示为####。
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
输出
id #### product #### good #### bad #### normal ##
1. axe #### 2 #### 3 #### 2
2. colgate #### 2 #### 1 #### 0
最佳答案
SELECT id, product, SUM(reactions = 'bad') AS bad, SUM(reactions = 'good') AS good,
SUM(reactions = 'normal') AS normal
FROM yourtable
GROUP BY product
关于php - 根据表中的产品获取计数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14907701/