我想写一个查询,它给出了下面的所有信息,但是我想要排除case_owner为null的所有信息,而Category_3是" CCA ..."。我仍然希望保留所有Category_3" CCA ...而不是null case_owner。我该怎么做?
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;
如果我在此之后添加此部分,它将不会为其他类别提供case_owner NULL。
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
答案 0 :(得分:0)
我明白了。通过
WHERE NOT(Category_3 IN ('CCA...')
AND case_owner IS NULL)
然后其余部分仍然相同。