Sql &引用;不是一个单一的组功能”;
嗨,我正在努力让下面的逻辑工作。但是它说没有一个功能组。。不确定原因。我想获取两个表中的记录,并将每个表的收入相加,以在第一个选择中累积总收入Sql &引用;不是一个单一的组功能”;,sql,oracle,Sql,Oracle,嗨,我正在努力让下面的逻辑工作。但是它说没有一个功能组。。不确定原因。我想获取两个表中的记录,并将每个表的收入相加,以在第一个选择中累积总收入 select ob_location_id, ib_location_id, vehicle_class, return_date, RENTAL_DATE, sum(revenue) as TotalRevenue from (select ob_location_id, ib_location_id, vehicle_class, ret
select ob_location_id,
ib_location_id,
vehicle_class,
return_date,
RENTAL_DATE,
sum(revenue) as TotalRevenue
from
(select ob_location_id,
ib_location_id,
vehicle_class,
return_date,
RENTAL_DATE,
SUM(DEMAND_TO_COME * BOARD_RATE) AS revenue
from PA_FCS_BLEND_FINAL) a
Union all
Select
ob_location_id,
ib_location_id,
vehicle_class,
return_date,
RENTAL_DATE,
sum(MATERIALIZED_BOH_REVENUE) as revenue
from PA_FCS_BLEND_BOH
group by
ob_location_id,
ib_location_id,
vehicle_class,
return_date,
RENTAL_DATE,
totalRevenue;
内联视图缺少a
子句GROUP BY
- 最后的
不应包含分组依据
总收入
SQL> SELECT ob_location_id,
2 ib_location_id,
3 vehicle_class,
4 return_date,
5 rental_date,
6 SUM (revenue) AS totalrevenue
7 FROM ( SELECT ob_location_id,
8 ib_location_id,
9 vehicle_class,
10 return_date,
11 rental_date,
12 SUM (demand_to_come * board_rate) AS revenue
13 FROM pa_fcs_blend_final
14 GROUP BY ob_location_id, --> this is missing
15 ib_location_id,
16 vehicle_class,
17 return_date,
18 rental_date) a
19 GROUP BY ob_location_id,
20 ib_location_id,
21 vehicle_class,
22 return_date,
23 rental_date
24 UNION ALL
25 SELECT ob_location_id,
26 ib_location_id,
27 vehicle_class,
28 return_date,
29 rental_date,
30 SUM (materialized_boh_revenue) AS revenue
31 FROM pa_fcs_blend_boh
32 GROUP BY ob_location_id,
33 ib_location_id,
34 vehicle_class,
35 return_date,
36 rental_date --> total_revenue (you had) shouldn't be here
37 /
OB_LOCATION_ID IB_LOCATION_ID VEHICLE_CLASS RETURN_DATE RENTAL_DATE TOTALREVENUE
-------------- -------------- ------------- ----------- ----------- ------------
1 2 3 4 5 42
1 2 3 4 5 6
SQL>
创建示例表之后,查询现在已经修复(这样就不会出现错误),但我不知道它是否返回您需要的结果。希望你能。请看一看。
SQL> SELECT ob_location_id,
2 ib_location_id,
3 vehicle_class,
4 return_date,
5 rental_date,
6 SUM (revenue) AS totalrevenue
7 FROM ( SELECT ob_location_id,
8 ib_location_id,
9 vehicle_class,
10 return_date,
11 rental_date,
12 SUM (demand_to_come * board_rate) AS revenue
13 FROM pa_fcs_blend_final
14 GROUP BY ob_location_id, --> this is missing
15 ib_location_id,
16 vehicle_class,
17 return_date,
18 rental_date) a
19 GROUP BY ob_location_id,
20 ib_location_id,
21 vehicle_class,
22 return_date,
23 rental_date
24 UNION ALL
25 SELECT ob_location_id,
26 ib_location_id,
27 vehicle_class,
28 return_date,
29 rental_date,
30 SUM (materialized_boh_revenue) AS revenue
31 FROM pa_fcs_blend_boh
32 GROUP BY ob_location_id,
33 ib_location_id,
34 vehicle_class,
35 return_date,
36 rental_date --> total_revenue (you had) shouldn't be here
37 /
OB_LOCATION_ID IB_LOCATION_ID VEHICLE_CLASS RETURN_DATE RENTAL_DATE TOTALREVENUE
-------------- -------------- ------------- ----------- ----------- ------------
1 2 3 4 5 42
1 2 3 4 5 6
SQL>