我一直在爲這段代碼苦苦掙扎了一段時間。我複製了它,並從另一個SO問題中修改了它,但我無法實現它。mysql:從table1中的表中選擇缺少的行0
我有一個表(分數),其中包含用戶名,用戶名和分數。和另一個名爲userLocations的表,其中包含userID,城市,國家,經緯度和長度座標。
我需要做的是列出scores-table中的每一行,這個行在表userLocation中沒有一個具有相同userID的行。
select scores.userID , case when userLocations.userID is not null then 1 else 0 end as row_exists from scores left outer join (select distinct userID from userLocations) userLocations on scores.userID = userLocations.userID
選擇x * FROM分數X LEFT JOIN用戶位置是開y.userid = x.user WHERE y.userid IS NULL – Strawberry 2014-11-01 16:04:08