我沒有看到一個問題,你的查詢(儘管場景S_8您的預期輸出是錯誤的,再加上你的where子句中使用的情況下s以上):
with table1 as (select 'A' name, 123 id, 'S_1' scenario, 2 timespend from dual union all
select 'A' name, 123 id, 'S_1' scenario, 5 timespend from dual union all
select 'A' name, 123 id, 'S_3' scenario, 6.3 timespend from dual union all
select 'B' name, 124 id, 'S_1' scenario, 3 timespend from dual union all
select 'B' name, 124 id, 'S_1' scenario, 8.9 timespend from dual union all
select 'B' name, 124 id, 'S_1' scenario, 5 timespend from dual union all
select 'B' name, 124 id, 'S_1' scenario, 4 timespend from dual union all
select 'B' name, 124 id, 'S_5' scenario, 1.23 timespend from dual union all
select 'B' name, 124 id, 'S_5' scenario, 56 timespend from dual union all
select 'B' name, 124 id, 'S_5' scenario, 8 timespend from dual union all
select 'B' name, 124 id, 'S_8' scenario, 9 timespend from dual union all
select 'B' name, 124 id, 'S_8' scenario, 4 timespend from dual union all
select 'C' name, 125 id, 'S_8' scenario, 6 timespend from dual union all
select 'D' name, 126 id, 'S_2' scenario, 9 timespend from dual union all
select 'D' name, 126 id, 'S_4' scenario, 5 timespend from dual union all
select 'D' name, 126 id, 'S_4' scenario, 6.2 timespend from dual union all
select 'D' name, 126 id, 'S_4' scenario, 7 timespend from dual union all
select 'E' name, 127 id, 'S_1' scenario, 8 timespend from dual union all
select 'E' name, 127 id, 'S_1' scenario, 1 from dual)
-- end of mimicking your table1 with data in it. See SQL below:
select sum(timespend),
scenario
from table1
where scenario in ('S_1','S_3','S_4','S_5','S_8')
and name = 'B'
group by scenario
order by scenario;
SUM(TIMESPEND) SCENARIO
-------------- --------
20.9 S_1
65.23 S_5
13 S_8
也許,從事實判斷一些在您的樣本數據的場景數據的是小寫,你提到你要找的set of scenarios that look similar
,你可能需要以下呢?
select sum(timespend),
upper(scenario) scenario
from table1
where upper(scenario) in ('S_1','S_3','S_4','S_5','S_8')
and name = 'B'
group by upper(scenario)
order by upper(scenario);
您可以發佈您的查詢輸出和您需要的輸出嗎? – Aleksej
你想要的時間總和,你得到的時間總和。我現在很困惑。 –
我已更新我的查詢。我想timespend爲組場景,它可以查找名稱B.類似的總和,但我m到處總和 – surendar