SELECT T1.category, T1.sumCnt AS sumCnt, T1.changedCnt, COALESCE(T2.deletedCnt, 0)
FROM(
SELECT COALESCE(category, 0) AS category, COUNT(id) AS sumCnt, SUM(CASE WHEN createdate != changedate AND SUBSTR(changedate,1,10) = '2015-01-26' THEN 1 ELSE 0 END) AS changedCnt
FROM metadata
GROUP BY category
) AS T1
LEFT OUTER JOIN
(SELECT COALESCE(category, 0) AS category, SUM(CASE WHEN TO_CHAR(deletiondate,'YYYY-MM-DD') = '2015-01-26' THEN 1 ELSE 0 END) AS deletedCnt
FROM deletedmetadata
GROUP BY category
)AS T2
ON T1.category = T2.category
FROM(
SELECT COALESCE(category, 0) AS category, COUNT(id) AS sumCnt, SUM(CASE WHEN createdate != changedate AND SUBSTR(changedate,1,10) = '2015-01-26' THEN 1 ELSE 0 END) AS changedCnt
FROM metadata
GROUP BY category
) AS T1
LEFT OUTER JOIN
(SELECT COALESCE(category, 0) AS category, SUM(CASE WHEN TO_CHAR(deletiondate,'YYYY-MM-DD') = '2015-01-26' THEN 1 ELSE 0 END) AS deletedCnt
FROM deletedmetadata
GROUP BY category
)AS T2
ON T1.category = T2.category
'IT > DB' 카테고리의 다른 글
[Oracle SQL] merge into를 사용하여 insert 와 update (0) | 2015.11.21 |
---|---|
[MariaDB] CentOS에 MariaDB(MySQL) 설치 및 사용 (0) | 2015.08.12 |
[Oracle SQL] 요일 호출 (0) | 2015.07.27 |
[Oracle SQL] 1컬럼 2컬럼의 값을 그대로 입력할경우 (0) | 2015.07.27 |
[Oracle SQL] international age 계산하는 SQL (0) | 2015.07.27 |