0

我有 2 个表:电路(id_电路,距离)和电路语言(id_电路语言,#id 电路,语言,标题)。我想获得超过 2 种语言的电路列表。

4

3 回答 3

1

join是必要的:

select cl.id_circuit
from circuit_langue cl
group by cl.id_circuit
having count(*) >= 3;

这假定表中没有重复项。如果有,那么您想使用count(distinct language) >= 3.

于 2018-11-11T19:41:03.533 回答
0

你需要像这样group by使用having

select c.id_circuit, count(cl.id_curcuit_language) as RecCount
from circuit c
inner join circuit_langue cl on c.id_circuit = cl.#id_circuit
group by c.id_circuit
having count(cl.id_curcuit_language) > 2
于 2018-11-11T19:38:54.260 回答
0

你可以试试这个(甲骨文风格):

select circuit.*
from circuit,
    (select id_circuit
    from circuit_langue
    group by id_circuit
    having count(*) >2 ) lang
where circuit.id_circuit = lang.id_circuit;  

此查询为您提供电路表中的整行,因此您可以访问任何列。另一方面,如果您只需要“id_circuit”列,那么 Gordon Linoff 的答案是最好的。

于 2018-11-11T20:41:46.110 回答