How to select based on summary?(s24)


If I have a table and here are the rows:

ODR_NO  PAY_RATE QTY  PRICE
----------------------------------------------------
A0001          10                   5          10000
A0001          20                   5          10000
A0001          70                   5          10000
B0001          30                 10            2000
B0001          50                 10            2000
C0001          40                   8          15000
C0001          60                   8          15000
D0001          80                   1          20000

I want to select where SUM(PAY_RATE) = 100 ,
How to return the results?

ODR_NO  PAY_RATE QTY  PRICE
----------------------------------------------------
A0001          10                   5          10000
A0001          20                   5          10000
A0001          70                   5          10000
C0001          40                   8          15000
C0001          60                   8          15000



Ans:

SELECT * FROM my_table
   WHERE odr_no IN
      (SELECT col_1 FROM
         (SELECT odr_no col_1, SUM(pay_rate) col_2 FROM my_table
           GROUP BY odr_no)
       WHERE col_2 = 100);

select * from contrat
where code_org_2 in
(select aa from
(select code_org_2 aa,sum(taux_majoration_reg_eloignee) bb from contrat
group by code_org_2)
where bb>80)
 

Hosted by www.Geocities.ws

1