简体   繁体   English

如何在 Oracle SQL 中仅对某些组织运行查询条件

[英]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.最后两个条件应该只对 orgs 1 和 2 运行,而不是对 org 3 运行。 org 的字段名称是 org_id。

i dont know which table org_id belongs to , so i just added it as org_id below.我不知道 org_id 属于哪个表,所以我只是在下面将它添加为org_id Just some extra pharantesis and OR condition can do the trick i think, just make sure that org_id doesnt contain null's :只是一些额外的 pharantesis 和OR条件可以做我认为的伎俩,只要确保org_id不包含空值:

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)               
              )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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