我有一个电车站台,我想选择具有公共电台的SQL查询线。
Ligne |Station
--------------
1 |2\n
1 |3\n
2 |1\n
2 |2\n
3 |4\n
结果将是电台2,因为它是1号线和2号线之间的公共电台:2。
答案 0 :(得分:0)
此查询将通过按站分组然后计算不同的行数来返回多行上的每个站的列表。然后,Having子句过滤掉任何有1行的站点。
SELECT
station,
COUNT(DISTINCT linge) --the count of distinct lines for each station
FROM table
GROUP BY station
HAVING COUNT(DISTINCT linge) > 1 --filters to a list of stations that have more than 1 line
答案 1 :(得分:0)
我的两分钱:
SELECT Ligne
FROM stations
GROUP BY Station
HAVING COUNT(*)>1