0

合計された列のMAX値のみを選択しようとしています

select rental.member_id,
       rental.rental_id,
       sum(rental_line.Qty) as TotalRentals
  from Rental 
 INNER JOIN rental_line 
    on rental.rental_id =rental_line.rental_id 
where MONTHS_BETWEEN(sysdate, datein)<(12)
group by rental.member_id, 
         rental.rental_id, 
         SUM(TotalRentals) =  MAX(SUM(TotalRentals));

何か案は?

4

1 に答える 1

1

(3) でクエリの結果セットをTotalRentals降順で並べ替え、rownum疑似列を使用して最初の行を取得できます。

select member_id
     , rental_id
     , TotalRentals
  from ( select rental.member_id
              , rental.rental_id
              , sum(rental_line.Qty) as TotalRentals
           from Rental 
          INNER JOIN rental_line 
             on rental.rental_id =rental_line.rental_id 
          where MONTHS_BETWEEN(sysdate, datein)<(12)
          group by rental.member_id, 
                   rental.rental_id
          order by 3 desc
      ) 
where rownum = 1
于 2012-12-02T20:47:57.207 に答える