查询会员表里开通会员数量大于10的会员省份及对应会员数量,并把省份名称从地址表里匹配出来
group by 分组,功能类似于EXCEL的数据透视,可以通过count(*)等对分组结果进行运算,注意查询的元素都必须包含在分组group by后面
having 添加分组筛选条件
order by 可多重排序,根据会员数量降序:desc ,会员数量相同时根据省份ID升序:asc
select m.Province,S.Name,count(*)
from member as m,ShippingArea as s
where m.Status=1
and m.Province=s.ShippingAreaID
group by m.Province,S.Name having count(*)>10
order by count(*) desc,m.Province asc;