I am facing a problem with GROUP BY clause, and the data is not showing up as I would like to have:
I have the data like this:
-------------------------------------------------------------------
| Company | Division | Business Area | Unit | Name Full | ID |
-------------------------------------------------------------------
| Company 1 | Div 1 | Business 1 | Unit 1 | Customer 1 | 01 |
| Company 1 | Div 1 | Business 1 | Unit 1 | Customer 2 | 02 |
| Company 1 | Div 1 | Business 1 | Unit 2 | Customer 3 | 03 |
| Company 1 | Div 1 | Business 3 | Unit 3 | Customer 2 | 02 |
| Company 1 | Div 2 | Business 1 | Unit 1 | Customer 4 | 04 |
....
....
In UI, I would like to have it displayed like this:
Company 1, Div 1, Business 1, Unit 1
-- Customer 1 01
-- Customer 2 02
Company 1, Div 1, Business 1, Unit 2
-- Customer 3 03
Company 1, Div 1, Business 3, Unit 3
-- Customer 2 02
Company 1, Div 2, Business 1, Unit 1
-- Customer 4 04
I tried the query, and if I try to group by only using company, div, business and unit then I get the error: 00979: not a group by expression as I am not using all columns as I used in SELECT, but then I don’t get my required result.
Any idea how may I proceed?
Jaanna,
Your example dataset has 5 rows and your expected output contains 9 rows. Those extra 4 rows are aggregations per (company,division,business_area,unit) where name_full and id are being rolled up.
Your example data:
The query:
You might want to conditionally display some column values or not, but I leave that as an exercise to you.
Regards,
Rob.