Skip to content
Advertisement

Display duplicate row indicator and get only one row when duplicate

I built the schema at http://sqlfiddle.com/#!18/7e9e3

I would like to write a query that would produce the following result characteristics :

  1. Returns only one owner per boat
  2. When multiple owners on a single boat, return the youngest owner.
  3. Display a column to indicate if a boat has multiple owners.

So the following data set when apply that query would produce

enter image description here

I tried

but haven’t had much luck so far.

Advertisement

Answer

This is just a case of numbering the rows for each BoatId group and also counting the rows in each group, then filtering accordingly:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement