mysql语法记录

mysql 在查询结果中进行二次查询

count(id)、max(id)、是结合 group by id,一起使用的

# 第一次查询:查询身份证编号和出现次数
select cardid,count(cardid) as total from p_person_info group by cardid;

# 在第一次查询结果进行二次查询:查询身份证出现次数大于1以上
select cardid from (select cardid,count(cardid) as total from p_person_info group by cardid) temp where temp.total>1;

# 在第一次查询结果进行二次查询:查询字段是否在列表内的
SELECT * FROM (SELECT * FROM `protocol_test` WHERE `_name` LIKE '%aaa%' ORDER BY `id`) as temp WHERE temp.protocol_type in('4','5') ORDER BY temp.id;

 

posted @ 2022-07-19 16:15  一只琥珀  阅读(38)  评论(0)    收藏  举报