假设我有 2 个表:Human、Car。 Table Car 有一些列,其中之一是 Human_id。例如,像这样:
Human_id Type
1 BMW
5 Mercedes
1 Audi
2 Peugeot
3 BMW
2 JEEP
我如何选择所有拥有不止一辆汽车的人?我的意思是我需要控制是否在 Human_id 列中多次使用 Human_id。但是我该怎么做呢?
SELECT human.name
FROM Human, Car
WHERE .... <- what goes here??
最佳答案
SELECT human.name, car.human_id, count(*) as total
FROM Human, Car
group by human.name, car.human_id
having count(*) > 1
关于postgresql - postgres查询(不止功能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10785640/