Skip to content
Advertisement

How to Select and Order By columns not in Groupy By SQL statement – Oracle

I have the following statement:

There exists some extra columns in table Positions that I want as output for “display data” but I don’t want in the group by statement.

These are Site, Desk

Final output would have the following columns:

Ideally I’d want the data sorted like:

How to achieve this?

Advertisement

Answer

It does not make sense to include columns that are not part of the GROUP BY clause. Consider if you have a MIN(X), MAX(Y) in the SELECT clause, which row should other columns (not grouped) come from?

If your Oracle version is recent enough, you can use SUM – OVER() to show the SUM (grouped) against every data row.

Alternatively, you need to make an aggregate out of the Site, Desk columns

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