728x90
SMALL
ratio_stdr_cd에 각각 RS00101,RS00102,RS00103,RS00104,RS00105가 있는데 얘네의 데이터들이 몇개나 있는지 확인할 때
쿼리 하나만 쓰는게 아니라 한번에 보고싶을 때 쓰는 쿼리
filter 사용
select * from t_ratio_cd trc ;
select
count(1) filter (where ratio_stdr_cd = 'RS00101') as "RS00101",
count(1) filter (where ratio_stdr_cd = 'RS00102') as "RS00102",
count(1) filter (where ratio_stdr_cd = 'RS00103') as "RS00103",
count(1) filter (where ratio_stdr_cd = 'RS00104') as "RS00104",
count(1) filter (where ratio_stdr_cd = 'RS00105') as "RS00105"
from t_ratio_cd ;
그러면 이렇게 잘나옴
RS00101|RS00102|RS00103|RS00104|RS00105|
-------+-------+-------+-------+-------+
13| 14| 7| 6| 18|
728x90
LIST
'DB > Postgresql' 카테고리의 다른 글
postgresql 실행중인 쿼리 확인, lock된 쿼리문 강제종류 (0) | 2021.12.02 |
---|---|
[postgresql] case when true false 조건에 따라 출력하는법, 중복방지 글쓰기 (0) | 2021.11.15 |
통계 최종쿼리 (0) | 2021.11.11 |
코드 매핑작업; a_code에 해당하는 b_code를 매핑테이블을 활용해 넣어주기 (0) | 2021.11.10 |
[Postgresql] 외부접속 허용하기, unable to connect to server (0) | 2021.07.27 |
댓글