3

有两个表:A,行(row_id,column1,...)和 B,行(column2,...)。

Select * from A
   join B on A.column1 = B.column2

表 B 中可以有 1 条或多条记录,其中 column2 = A.column1。B 中的每条记录在 A 中都有匹配的记录,但并非 A 中的每条记录都有 B 中的记录。

什么是获取row_id表 A 中的有效查询,表 B 中有超过 100 条记录与之关联?

4

2 回答 2

3

这将为您提供表 A 中的所有列:

select A.*
from A
inner join (
    select column2
    from B
    group by column2
    having count(*) > 100
) BC on A.column1 = BC.column2

如果您只需要 ID,则可以执行以下操作:

select column2
from B
group by column2
having count(*) > 100
于 2012-06-27T14:55:46.500 回答
3
SELECT `row_id`
FROM `A`
JOIN `B` ON (`B`.`column2` = `A`.`column1`)
GROUP BY `A`.`row_id`
HAVING COUNT(*) > 100
于 2012-06-27T14:56:03.147 回答