我有一个表名CITY,这两列有'CITY_ID'和'PLACES'
我正在尝试获得CITY_ID,它应该只有这四个地方德州,阿拉巴马州,亚利桑那州,科罗拉多州,它不应该有任何其他地方。
select city_id from city
where places in ('texas','alabama','arizona','colorado')
having count(city_id)=4
group by city_id
结果:我收到了很多包含这四个地方和其他地方的city_id。
请帮助
答案 0 :(得分:0)
尝试执行以下操作
SELECT C._city_id FROM
(SELECT city_id, places, count(places) as numplaces FROM Cities group by city_id) as C
WHERE C.places in ('texas', 'alabama','arizona','colorado') AND C.numplaces = 4
请注意,我的示例是在MySQL中完成的,如果需要,您必须调整SQL。
答案 1 :(得分:0)
从城市中选择不同的city_id ('texas','alabama','arizona','colorado')的地方;
应该有用。