粘貼當前正在使用的sql查詢以從unix shell腳本生成報告。我想在下面的sql查詢中添加一列COUNT(cdw.file_id)writeoffcnt,它顯示與mg_disp_status = 0和mig_disp_code = 3相匹配的記錄的 計數。 現有字段COUNT(cdw.file_id)cnt應具有匹配 mg_disp_status = 1和mig_disp_code <> 2的記錄計數。如何修改查詢?SQL查詢分組:
SELECT fs.file_id,
fs.file_id_serv,
fs.file_process_dt,
fs.file_name,
fs.total_records,
RTRIM (d.description_text) source,
SUM(amount),
COUNT (cdw.file_id) cnt
FROM file_status fs,
dr_data_work cdw,
descriptions d,
contacts ec
WHERE file_process_dt >= TO_DATE ('${START_DATE}', 'DD-MON-YYYY')
AND file_process_dt < TO_DATE ('${END_DATE}', 'DD-MON-YYYY')
AND fs.ext_contact_id = ec.ext_contact_id
--
AND ec.description_code = d.description_code
AND cdw.file_id = fs.file_id
AND mg_disp_status = 1
AND mig_disp_code <> 2
GROUP BY fs.file_id,
fs.file_id_serv,
fs.file_process_dt,
fs.file_name,
fs.total_records,
RTRIM (d.description_text);
非常感謝您的信息 – Arav 2011-06-23 05:42:31