简体   繁体   中英

How to run a query condition for only certain organizations in Oracle SQL

I have a query which has a condition to eliminate certain rows from the output. I need this condition to run for only two organizations. For the rest it should by pass the condition and return all the rows. This is the query

        SELECT lines.customer_trx_id customer_trx_id,
               lines.unit_selling_price,
               lines.customer_trx_line_id customer_trx_line_id
           FROM mtl_units_of_measure uom,
                ra_customer_trx_lines_all lines,
                ra_customer_trx_all trx
        WHERE trx.customer_trx_id = lines.customer_trx_id
              AND trx.complete_flag = 'Y'
              AND lines.uom_code = uom.uom_code(+)
              AND lines.line_type = 'LINE'
              AND trx.customer_Trx_id =1
              AND lines.unit_selling_price <>0
              AND lines.description NOT LIKE '%PROM%DISCOUNT%'
              AND lines.description NOT LIKE '%TIER%DISCOUNT%'

The last two conditions should run for only orgs 1 and 2 but not for org 3. the field name for org is org_id.

i dont know which table org_id belongs to , so i just added it as org_id below. Just some extra pharantesis and OR condition can do the trick i think, just make sure that org_id doesnt contain null's :

SELECT lines.customer_trx_id customer_trx_id,
               lines.unit_selling_price,
               lines.customer_trx_line_id customer_trx_line_id
           FROM mtl_units_of_measure uom,
                ra_customer_trx_lines_all lines,
                ra_customer_trx_all trx
        WHERE trx.customer_trx_id = lines.customer_trx_id
              AND trx.complete_flag = 'Y'
              AND lines.uom_code = uom.uom_code(+)
              AND lines.line_type = 'LINE'
              AND trx.customer_Trx_id =1
              AND lines.unit_selling_price <>0
              AND 
             ( (lines.description NOT LIKE '%PROM%DISCOUNT%'
               AND lines.description NOT LIKE '%TIER%DISCOUNT%'
               and org_id in (1,2)) or 
               org_id not in (1,2)               
              )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM