我没有看到一个问题,你的查询(尽管场景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