Skip to content
Advertisement

Display individual elements from grouped rows on same row

I want to both group some rows together but return 1 column of the individual rows from the group onto the same line as well, probably easiest to show with an example….

Original Data

Grouped by rDate, track, AVG(odds)

Desired output, grouped with average odds but with individual odds added to grouped row as well:

The number of rows in each group varies from 4 to 8, but a solution using a fixed number of rows would be acceptable, I can work around it.

Advertisement

Answer

I would suggest conditional aggregation phrased like this:

Note: If you want to extend this to 8 columns for odds, just follow the pattern in the SELECT.

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