1 / 7

SELECT S.rating, MIN (S.age) AS minage FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating

SELECT S.rating, MIN (S.age) AS minage FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating HAVING COUNT (*) > 1. Step 1: Evaluate FROM subqueries. Helps to think of it like: FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating SELECT S.rating, MIN (S.age) AS minage HAVING COUNT (*) > 1.

erincapers
Download Presentation

SELECT S.rating, MIN (S.age) AS minage FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SELECT S.rating, MIN (S.age) AS minage FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating HAVING COUNT (*) > 1

  2. Step 1: Evaluate FROM subqueries Helps to think of it like: FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating SELECT S.rating, MIN (S.age) AS minage HAVING COUNT (*) > 1 Nothing to see here!

  3. Step 2: evaluate WHERE FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating SELECT S.rating, MIN (S.age) AS minage HAVING COUNT (*) > 1

  4. Step 3: GROUP BY S.rating

  5. Step 4: SELECT S.rating, MIN (S.age) AS minage Keeping the original rows around…

  6. Step 5: HAVING COUNT (*) > 1 … for the HAVING clause!

  7. Result Takeaway: since groups are not formed yet, trying to do an aggregate expression in the WHERE clause doesn’t make sense in this model of SQL evaluation.

More Related