用sql语句实现查询多个表中某字段出现的次数大于某个数值的语句

2024-11-27 19:31:06
推荐回答(2个)
回答1:

SELECT Q,COUNT(*) 出现总次数

FROM (SELECT Q FROM 表1 UNION ALL SELECT Q FROM 表2)
GROUP BY Q
HAVING COUNT(*)>10

回答2:

表 a ....,total,...
表 b ...,total,...
查询 a,b 中 total 含有 各种可能相同的数据

select * from a
where total in (select total from a group by total having count(total) > 10)
union
select * from b
where total in (select total from b group by total having count(total) > 10)
;