简体   繁体   中英

How do I exclude certain information inside the columns using SQL?

I want to write a query that gives me all the information below, but I want to exclude all the information that has the case_owner is null AND the Category_3 is "CCA...".And I still want to keep all the Category_3 "CCA... with not null case_owner. How do I do that?

SELECT      rt.name as CR ,ds.date_sk
            , CAST (u.name as VARCHAR(161)) as Case_owner
            , QUEUE_NAME__C as Queue_Name
            , CAST(sf.casenumber as VARCHAR(13)) as Casenumber  
            , CAST (sf.Product_Level_1__c as VARCHAR(1000)) as Category_1
            , CAST (sf.Product_Level_2__c as VARCHAR(1000)) as Category_2
            , CAST (sf.Product_Level_3__c as VARCHAR(1000)) as Category_3      
            ,sf.PROCESSING_TIME__C  
--,count(*) Cases
FROM            dwh.v_dim_sf_case sf
JOIN            dwh.v_dim_date ds
ON              CAST(sf.createddate as date) = ds.date_sk
LEFT JOIN       DWH.V_DIM_SF_user u
ON              sf.ownerid = u.id  --and sf.LASTMODIFIEDBYID = u.id
JOIN            dwh.V_DIM_SF_RECORD_TYPE rt
ON              sf.recordtypeid = rt.id
WHERE           ds.date_SK BETWEEN '2017-02-01' AND date -1
AND             sf.QUEUE_NAME__C IS NOT NULL
AND             sf.recordtypeid IN ('01232000000UO9zAAG')
AND             case_owner is not null
AND             Category_1 is not null
AND             Category_2 is not null
AND             Category_3 is not null                          
AND             sf.STATUS NOT IN ( 'Duplicate','SPAM/junk')
AND             sf.CASE_TYPE NOT IN('Bugs/Research','Holding','Provisioning','Research Provisioning')

GROUP BY        1,2,3,4,5,6,7,8,9;

And if I add this part after that, it will not give me the case_owner NULL for other categories.

EXCEPT         
SELECT      rt.name as CR ,ds.date_sk
            , CAST (u.name as VARCHAR(161)) as Case_owner
            , QUEUE_NAME__C as Queue_Name
            , CAST(sf.casenumber as VARCHAR(13)) as Casenumber  
            , CAST (sf.Product_Level_1__c as VARCHAR(1000)) as Category_1
            , CAST (sf.Product_Level_2__c as VARCHAR(1000)) as Category_2
            , CAST (sf.Product_Level_3__c as VARCHAR(1000)) as Category_3      
            ,sf.PROCESSING_TIME__C  
--,count(*) Cases
FROM            dwh.v_dim_sf_case sf
JOIN            dwh.v_dim_date ds
ON              CAST(sf.createddate as date) = ds.date_sk
LEFT JOIN       DWH.V_DIM_SF_user u
ON              sf.ownerid = u.id  --and sf.LASTMODIFIEDBYID = u.id
JOIN            dwh.V_DIM_SF_RECORD_TYPE rt
ON              sf.recordtypeid = rt.id
WHERE           Category_3 NOT IN ('CCA Auth Status Not Changing')
AND             case_owner is null  

I figure it out. By putting

WHERE    NOT(Category_3 IN ('CCA...')
AND      case_owner IS NULL)

and then the rest is still the same.

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