0

PEGA ID という 1 つの列を持つテーブルがあり、その列には 111、222 などの値があり、いくつかの 0 もあります。すべての 0 の下で qry を実行すると、フィルターが適用されます。これらの 0 をカウントするにはどうすればよいですか?ユニオンを使用できますか?

SELECT  
    ivr.dw_dealer_id, 
    ivr.dw_product_id, 
    ivr.dw_program_type_id, 
    ivr.dw_month_id, 
    TO_CHAR(ivr_update_dt, 'YYYYMM') buss_month, 
    count(*)
FROM  idm_ivr_interaction ivr, stgdba.interactions intr
WHERE ivr.cti_rec_id = intr.pega_id
4

1 に答える 1

0

編集: OP0が null ではないことを具体的に述べたので、クエリを use に変更しますcase

count(case when ivr.dw_dealer_id = 0 then 1 else ivr.dw_dealer_id end)

または、 last でクエリを使用するだけORです。

SELECT  
        ivr.dw_dealer_id, 
        ivr.dw_product_id, 
        ivr.dw_program_type_id, 
        ivr.dw_month_id, 
        TO_CHAR(ivr_update_dt, 'YYYYMM') buss_month, 
        count(ivr.dw_dealer_id) as counts
    FROM  idm_ivr_interaction ivr, stgdba.interactions intr
    WHERE ivr.cti_rec_id = intr.pega_id
    AND (intr.pega_id IS NULL OR ivr.cti_rec_id IS NULL)

nvlIDをラップしています...

SELECT  
    ivr.dw_dealer_id, 
    ivr.dw_product_id, 
    ivr.dw_program_type_id, 
    ivr.dw_month_id, 
    TO_CHAR(ivr_update_dt, 'YYYYMM') buss_month, 
    count(nvl(ivr.dw_dealer_id,1))
FROM  idm_ivr_interaction ivr, stgdba.interactions intr
WHERE ivr.cti_rec_id = intr.pega_id
AND (intr.pega_id IS NULL OR ivr.cti_rec_id IS NULL)
  • Group Byところで、あなたが使用している...があるはずcountです.......
于 2013-01-09T19:56:35.120 に答える