簡體   English   中英

“不是單組分組功能”

[英]“not a single-group group function”

嗨,我正在嘗試使以下邏輯正常工作。 但它說不是按功能分組。.不知道為什么..我想獲取兩個表中的記錄,然后將每個表的收入相加以在第一選擇中累計總收入。

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子句
  • 最后的GROUP BY不應包含TOTAL_REVENUE

一個虛擬的示例(日期類型當然不匹配,但是請不要介意):

SQL> CREATE TABLE pa_fcs_blend_final
  2  (
  3     ob_location_id  NUMBER,
  4     ib_location_id  NUMBER,
  5     vehicle_class   NUMBER,
  6     return_date     NUMBER,
  7     rental_date     NUMBER,
  8     demand_to_come  NUMBER,
  9     board_rate      NUMBER
 10  );

Table created.

SQL> insert into pa_fcs_blend_final values
  2  (1, 2, 3, 4, 5, 6, 7);

1 row created.

SQL> CREATE TABLE pa_fcs_blend_boh
  2  (
  3     ob_location_id            NUMBER,
  4     ib_location_id            NUMBER,
  5     vehicle_class             NUMBER,
  6     return_date               NUMBER,
  7     rental_date               NUMBER,
  8     materialized_boh_revenue  NUMBER
  9  );

Table created.

SQL> insert into pa_fcs_blend_boh values
  2  (1, 2, 3, 4, 5, 6);

1 row created.

查詢返回什么 ; 這是正確的嗎? 不知道。

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM