Если у меня есть таблица типа:
LOCATION CODE COMPANY PRICE
--------- ---- ------- ----------
Sydney | A | ACME | 1200
Brisbane | C | WONKA | 3000
Melbourne | B | ACME | 500
Sydney | A | ACME | 100
Brisbane | A | WONKA | 1000
Melbourne | C | ACME | 7000
Sydney | A | ACME | 800
Brisbane | B | WONKA | 900
Melbourne | C | WONKA | 200
Sydney | C | ACME | 400
Brisbane | B | ACME | 1200
Melbourne | D | WONKA | 600
Sydney | A | ACME | 3000
Brisbane | A | WONKA | 400
Melbourne | C | WONKA | 1400
Sydney | A | ACME | 1600
Brisbane | A | WONKA | 700
Melbourne | A | ACME | 800
, и я хочу получить что-то вроде:
LOCATION CODE COMPANY SUM(PRICE)
--------- ---- ----- ----------
Brisbane | A | WONKA | 2100
Brisbane | B | ACME | 1200
Brisbane | B | WONKA | 900
Brisbane | C | WONKA | 3000
Brisbane | | | 7200
Melbourne | A | ACME | 800
Melbourne | B | ACME | 500
Melbourne | C | ACME | 7000
Melbourne | C | WONKA | 1600
Melbourne | D | WONKA | 600
Melbourne | | | 10500
Sydney | A | ACME | 6700
Sydney | C | ACME | 400
Sydney | | | 7100
Это итоговые цены, сгруппированные по местоположению, коду и компании, сстрока итоговой цены (сгруппированная только по местоположению).
Первая часть может быть достигнута с помощью следующего запроса:
with sample_tab as
(
select 'Sydney' location,'A' code, 'ACME' company, 1200 price from dual
union all
select 'Brisbane' location,'C' code, 'WONKA' company, 3000 price from dual
union all
select 'Melbourne' location,'B' code, 'ACME' company, 500 price from dual
union all
select 'Sydney' location,'A' code, 'ACME' company, 100 price from dual
union all
select 'Brisbane' location,'A' code, 'WONKA' company, 1000 price from dual
union all
select 'Melbourne' location,'C' code, 'ACME' company, 7000 price from dual
union all
select 'Sydney' location,'A' code, 'ACME' company, 800 price from dual
union all
select 'Brisbane' location,'B' code, 'WONKA' company, 900 price from dual
union all
select 'Melbourne' location,'C' code, 'WONKA' company, 200 price from dual
union all
select 'Sydney' location,'C' code, 'ACME' company, 400 price from dual
union all
select 'Brisbane' location,'B' code, 'ACME' company, 1200 price from dual
union all
select 'Melbourne' location,'D' code, 'WONKA' company, 600 price from dual
union all
select 'Sydney' location,'A' code, 'ACME' company, 3000 price from dual
union all
select 'Brisbane' location,'A' code, 'WONKA' company, 400 price from dual
union all
select 'Melbourne' location,'C' code, 'WONKA' company, 1400 price from dual
union all
select 'Sydney' location,'A' code, 'ACME' company, 1600 price from dual
union all
select 'Brisbane' location,'A' code, 'WONKA' company, 700 price from dual
union all
select 'Melbourne' location,'A' code, 'ACME' company, 800 price from dual
)
select location,code,company,sum(price)
from sample_tab
group by location,code,company
order by location;
, но вы не знаете, как получить строки с помощью подпункта.Итого по местоположению.Может ли это быть достигнуто с помощью аналитических функций или других функций?