Mysql query using where and group by clause

后端 未结 2 1548
清酒与你
清酒与你 2020-12-20 11:56

I have the following table.

mysql> select * from consumer9;
+------------+--------------+-------------------+
| Service_ID | Service_Type | consumer_feedb         


        
相关标签:
2条回答
  • 2020-12-20 12:31

    Use the having clause instead of where

    SELECT  Service_ID, Service_Type, SUM(consumer_feedback) 
    FROM consumer9 
    GROUP BY Service_ID 
    HAVING Service_Type='Printer';
    

    Regards.

    0 讨论(0)
  • 2020-12-20 12:32

    The following query should work.

    select Service_ID, Service_Type, sum(consumer_feedback) 
    from consumer9 
    where Service_Type=Printer
    group by Service_ID, Service_Type;
    

    Remember, the where clause goes before the group by clause and all non-aggregated terms in the select part will have to be present in the group by clause.

    0 讨论(0)
提交回复
热议问题