-
[SQL]SELECT 결과 하나의 테이블로 합치기 (UNION, SELECT의 재SELECT)데이터베이스 2023. 1. 26. 14:52
select count(process_result)as 'success' from monitor_db.monitor_info where process_result = 'SUCCESS' UNION ALL select count(process_result)as 'fail' from monitor_db.monitor_info where process_result = 'FAIL';
UNION 만 써도 된다. 각각의 값이 구분지어져있기 때문에.
근데 내가 원하는건 success와 fail이 각기 다른 열로 출력되는건데, success로 묶여있다.
UNION은 원래 아래로 내려가는 것이기 때문
select( select count(process_result) from monitor_db.monitor_info where process_result = 'SUCCESS') as 'success', (select count(process_result)as 'fail' from monitor_db.monitor_info where process_result = 'FAIL')as 'fail';
SELECT한 값들을 다시 SELECT하니 원하는 형태가 이루어졌다.
반응형'데이터베이스' 카테고리의 다른 글
[MongoDB] mongo --version 등 cmd에서 mongo 명령어 실행이 안될 때 (0) 2023.06.27 INSERT INTO SELECT SUBQUERY : A컬럼 값을 B컬럼으로 복사하기 (0) 2023.02.07 mysql varchar 한글길이 (0) 2023.01.17 [SQL] INSERT INTO SELECT 문 & CASE WHEN 동시에 쓰기 (INSERT INTO 다중) (0) 2023.01.03 [SQL]조건부 INSERT (0) 2023.01.03