Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL statement to exclude certain rows of data

I have this SQL Query:

SELECT DISTINCT viewid, 
            relid, 
            Sum(kaiprddta.f0315le.rtaap *. 01)  AS OPEN, 
            Sum(kaiprddta.f0315le.rtcurr *. 01) AS CURRENT1, 
            Sum(kaiprddta.f0315le.rtftr *. 01)  AS FUTURE, 
            Sum(kaiprddta.f0315le.rtag1 *. 01)  AS AGE1, 
            Sum(kaiprddta.f0315le.rtag2 *. 01)  AS AGE2, 
            Sum(kaiprddta.f0315le.rtag3 *. 01)  AS AGE3, 
            rtcrcd, 
            Sum(kaiprddta.f0315le.rtag4 *. 01)  AS AGE4, 
            Sum(kaiprddta.f0315le.rtag5 *. 01)  AS AGE5, 
            Sum(kaiprddta.f0315le.rtag6 *. 01)  AS AGE6, 
            Sum(kaiprddta.f0315le.rtag7 *. 01)  AS AGE7, 
            rtco 
FROM   kaiprddta.f0315le, 
   kaiprddta.f55311 
WHERE  ( kaiprddta.f0315le.rtac06 = terr ) 
   AND ( viewid = 'Company' ) 
   AND ( rtco = '00001' 
          OR rtco = '00099' ) 
GROUP  BY viewid, 
      relid, 
      rtcrcd, 
      rtco 
ORDER  BY viewid, 
      relid, 
      rtcrcd 

Here's what it looks like now(I'm not allowed to embed images yet so if someone could edit it and make it embedded that would be awesome):

Sample

There is two RELID values "Region427" and "Region632" that both have 2 RTCO values "00001" and "00099". All the other rows of data have one RTCO value of "00001". The sql returns one row of data per RTCO value. I want to only return the row for RTCO value "00099" for "Region427" and "Region632". Can someone help me to modify my sql statement to achieve this

like image 409
KMurray Avatar asked Feb 17 '26 07:02

KMurray


1 Answers

AND ( (rtco = '00001' AND RELID!="Region427")
          OR (rtco = '00099' AND RELID="Region427")) 
like image 195
Ted at ORCL.Pro Avatar answered Feb 18 '26 20:02

Ted at ORCL.Pro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!