900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > where having group by order by count的使用注意

where having group by order by count的使用注意

时间:2021-07-16 09:07:21

相关推荐

where having group by order by count的使用注意

where、having、group by、order by、count的使用注意

1_where、having、group by、order by的顺序2_group by的作用3_where和group by的组合4_group by和having的组合5_where、having、group by的组合使用6_count与group by的组合使用

1_where、having、group by、order by的顺序

where、 group by、 having、 order by

2_group by的作用

注意事项:分组后只能对分组属性进行操作

错误举例:select name from table_name group by type

由于group by type ,所以分组属性是type,不能select name

3_where和group by的组合

先where进行按单个元组进行条件筛选,后通过group by对筛选后的集合进行分组

--选择库存编号大于10000并按种类分组select type from repertory_record where repertory_id > 10000 group by type

4_group by和having的组合

先where进行按单个元组进行条件筛选,再使用group by进行分组最后使用having对分组后的一个个集合进行操作

--先按照种类进行分组,再从这些组中挑选'杯子','电脑','耳机'这三类select type from repertory_record group by type having type in ('杯子','电脑','耳机')

5_where、having、group by的组合使用

使用group by进行分组,再使用having对分组后的一个个集合进行操作

--先使用where筛选编号大于10000的记录,再使用group by进行按种类分组,最后使用having在已经分好组的集合中选择种类不是'杯子','电脑','耳机'这三类的记录select type from repertory_record where repertory_id > 1000 group by type having type not in ('杯子','电脑','耳机')

6_count与group by的组合使用

--如上图所示为分组后的状态,分组后统计每个组的元组数目count(type)select type,count(type) from repertory_record where repertory_id < 10004 group by type

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。