728x90
writing-efficient-queries
-
캐글 advanced_sql/04-writing-efficient-queries<Kaggle-Course> 2023. 3. 15. 19:49
WITH LocationsAndOwners AS ( SELECT * FROM CostumeOwners co INNER JOIN CostumeLocations cl ON co.CostumeID = cl.CostumeID ), LastSeen AS ( SELECT CostumeID, MAX(Timestamp) FROM LocationsAndOwners GROUP BY CostumeID ) SELECT lo.CostumeID, Location FROM LocationsAndOwners lo INNER JOIN LastSeen ls ON lo.Timestamp = ls.Timestamp AND lo.CostumeID = ls.CostumeID WHERE OwnerID = MitzieOwnerID