# 使用 where 子句和 group by 子句进行汇总
select column_name1, column_name2 from tb_name
where
group by column_name1, column_name2;
where 子句先进行筛选,然后再与 group by 汇总处理
# 同时使用 where 子句和 group by子句
select * from tb_name
where column1_name = ‘abc’
group by column_name2;
# group by 与where 并用时,select 语句执行的顺序如下:
from - where - group by - select
tips : 在sql 语句中,书写顺序与DBMS内部执行顺序并不相同
# 聚合键 之外的列名写在select 子句中会出错
select product_name, product_price ,count(*) from tb_name
group by product_price
在这里因为 product_price 为聚合键,product_name 写在select子句中,即报错