以下查询尝试显示应用程序,已批准的应用程序以及针对特定状态完成的应用程序以及按月排序的应用程序的总计数。所以像这样:
State Applications Approvals Completed
TX 200 100 50
TX 150 75 48
但是我的计数太低了。我最初开始使用子查询,我发现这些查询效率很低,所以现在我尝试使用LEFT JOINS。我很感激为什么我的计数如此之低或者我在JOIN中的条件是否相关的任何想法。此外,申请获得批准或完成的条件是基于状态。
SELECT APPU_CUR_STATE,
COUNT(DISTINCT APPL_ID),
COUNT(DISTINCT APPD_ID),
COUNT(DISTINCT APDD_ID)
FROM APPL_APP
JOIN APPU_APP_USER ON APPU_APPL_ID = APPL_ID
JOIN APPS_APP_STATUS ON APPS_ID = APPL_APPS_ID
LEFT JOIN APPD_APP_DECISION ON APPL_ID = APPD_APPL_ID AND APPD_STATUS = 'LENDER_APPROVED'
LEFT JOIN APDD_APP_DEAL_DATA ON APDD_APPL_ID = APPL_ID AND APPS_STATUS IN('COMPLETE','NOTIFICATION_OF_FUND')
WHERE APPU_CUR_STATE = 'TX'
AND APPL_CREATE_DT >= '2014-01-01 00:00:00'
GROUP BY MONTH(APPL_CREATE_DT);