数据库group by语句select * from hb_student_info where card_id in(select card_id from hb_student_info group by card_id having count(card_id)>1)我知道这句的功能是查找出card_id相同的纪录 具体是怎么实现功能的,count函数
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/29 03:42:05
数据库group by语句select * from hb_student_info where card_id in(select card_id from hb_student_info group by card_id having count(card_id)>1)我知道这句的功能是查找出card_id相同的纪录 具体是怎么实现功能的,count函数
数据库group by语句
select * from hb_student_info where card_id in(select card_id from hb_student_info group by card_id having count(card_id)>1)
我知道这句的功能是查找出card_id相同的纪录 具体是怎么实现功能的,count函数大于1是什么意思?
数据库group by语句select * from hb_student_info where card_id in(select card_id from hb_student_info group by card_id having count(card_id)>1)我知道这句的功能是查找出card_id相同的纪录 具体是怎么实现功能的,count函数
select card_id from hb_student_info group by card_id having count(card_id)>1
group by 是按照card_id分组,配合having做条件筛选
比如hb_student_info中数据如下:
card_id 栏位1 栏位2
001 1 2
001 2 2
001 3 4
002 4 4
003 4 4
003 2 3
通过group by 分组后
card_id
001
002
003
此时在select 中加入count(card_id) 去看 select card_id,count(card_id)from hb_student_info group by card_id
card_id count(card_id)
001 3
002 1
003 2
通过这样的数据就可以看出 只有001和003是符合条件的(即card_id有相同的记录)
in 后面的查询条件就是通过筛选分组后card_id>1的数目找出所有的card_id