我有以下查询:
String
我现在拥有的:一张有3列的表格:机场名称,包含找到的行李数量和丢失的行李数量。 它只显示填充两列时的机场(行)。
我想要两件事:
我用When等试过这个但是它一直给我错误。我也尝试了EXISTS,但我是SQL的新手,所以我不知道它是如何工作的......
有人有解决方案吗?
亲切的问候,
LTKort
答案 0 :(得分:1)
这适用于两种情况:
SELECT airportname, COUNT(DISTINCT foundBag.id) countFound, COUNT(DISTINCT lostBag.id) countLost
FROM airports
LEFT JOIN foundBag ON airport_id = foundBag.airportDest
LEFT JOIN lostBag ON airport_id = lostBag.airportDest
WHERE foundBag.airportDest is not null
or lostBag.airportDest is not null
GROUP BY airport.airportname