简体   繁体   English

<SQL>如何编辑EXISTS查询

[英]<SQL> How to edit EXISTS query

I have a query that has EXISTS query, which has PRCS_STE_CD column. 我有一个具有EXISTS查询的查询,该查询具有PRCS_STE_CD列。 QUERY 查询

SELECT          
    PRCS_SNO
          , YEAR
          , SUBSC_CANC_YN                             
    FROM
        TB_POT_ECD_PRCS_INFO INF
    WHERE
        INF.SUBSC_CANC_YN = 'N'
        AND EXISTS (
                   SELECT 'X'
                   FROM TB_POT_ECD_PRCS_HIST HIS
                   WHERE PRCS_STE_CD = 'R01'
                   )

Idea is to show only ones that PRCS_STE_CD = 'R01'. 想法是仅显示PRCS_STE_CD ='R01'的那些。

But the problem is that some have 'R01' and 'R02' for PRCS_STE_CD. 但是问题在于,某些PRCS_STE_CD具有“ R01”和“ R02”。

(In this case, where it has both R01 and R02, I do not want to show it on the list.) (在这种情况下,它同时具有R01和R02,我不想在列表上显示它。)

Basiacally, I want to show one that only has R01 for PRCS_STE_CD. Basiacally,我想显示一个仅针对PRCS_STE_CD的R01。

Oh and PRCS_STE_CD CAN NOT have only R02. 哦,PRCS_STE_CD 不能只有R02。 It must have R01 in order to have R02. 它必须具有R01才能具有R02。

And again, when it has both R01, R02, it should not be selected on the list. 同样,当它同时具有R01,R02时,不应在列表中选择它。

Can anyone help editing the query? 谁能帮忙编辑查询?

In your table how have you stored R02 for PRCS_STE_CD. 在您的表中,如何存储PRCS_STE_CD的R02。 I assume you have a different column to store R02. 我假设您有另一列存储R02。 If so then you can try using the IN and the OR Operators as. 如果是这样,那么您可以尝试将IN和OR运算符用作。

SELECT      
    PRCS_SNO, YEAR, SUBSC_CANC_YN                             
    FROM TB_POT_ECD_PRCS_INFO INF
    WHERE INF.SUBSC_CANC_YN = 'N'
    AND 'X' IN (
                SELECT 'X'
                FROM TB_POT_ECD_PRCS_HIST HIS
                WHERE PRCS_STE_CD = 'R01' OR Second_Column= 'R02'
               )

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

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