0

総費用が 230 を超え、そのツアーの人数が 7 人を超える前に、ツアーの日付とサイト名を選択したい。完全なコードは以下のとおりです。ユニオンの最初の部分が機能します。

SELECT tour_date AS "Departure Date",  site_name "Site Name"
FROM partres, reservation, tour, site
WHERE partres.res_id = reservation.res_id
  AND reservation.tour_id = tour.tour_id
  AND tour.site_id = site.site_id
GROUP BY tour_date, site_name
HAVING COUNT(part_id) > 7

  UNION

SELECT tour_date AS "Departure Date",  site_name "Site Name"
FROM (
  SELECT res_id,tour_date,site_name, (res_partcost +NVL(RES_GEARCOST,0)) as "total_cost" 
  FROM reservation,site,tour) 
WHERE  reservation.tour_id = tour.tour_id
  AND tour.site_id = site.site_id
  AND total_cost > 230
GROUP BY tour_date, site_name;

私はまだエラーが発生しました

ORA-00904: "TOTAL_COST": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 437 Column: 7

ありがとう

4

2 に答える 2

2

結合条件をサブクエリ内に移動する必要があります

SELECT tour_date AS "Departure Date",  site_name "Site Name"
FROM (
    SELECT res_id,tour_date,site_name, (res_partcost +NVL(RES_GEARCOST,0)) as "total_cost" 
    FROM reservation,site,tour
    WHERE reservation.tour_id = tour.tour_id
    AND tour.site_id = site.site_id ) Res1
WHERE Res1.total_cost > 230 // this will not be displayed in a result
GROUP BY tour_date, site_name;
于 2013-05-29T23:01:36.423 に答える