Mysql基础第十六天,分组数据
原创
©著作权归作者所有:来自51CTO博客作者2019ab的原创作品,请联系作者获取转载授权,否则将追究法律责任
分组数据
select count(vend_ic) from products where vend_id>10001;
创建分组
select count(prod_ic),vend_id,vend_price from products group by vend_price; // group by 分组数据
过滤分组
select count(vend_ic),vend_id from products where vend_id>10001 group by vend_id;//where vend_id>10001
select count(vend_ic),vend_id from products group by vend_id having(conunt(vend_ic)) >= 5;
select count(vend_ic),vend_id from products group by vend_id having(count(vend_ic)) between 3 and 10;
分组和排序
select count(vend_ic),vend_id from products group by vend_id order by count(vend_ic) desc; // 降序
select子句顺序
select count(vend_ic),vend_id from products where vend_id>1000 group by vend_id having count(vend_ic)>1 order by count(vend_ic) desc; // 降序