Cute Happy Ghost
본문 바로가기
DB/Postgresql

postgresql count여러개 보기 각 카테고리별 항목수 확인

by JENN_tech7 2021. 11. 15.
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

댓글