[MySQL] count 조건 및 방법

seonjeong·2023년 4월 30일

MySQL

목록 보기
7/9
post-thumbnail

🔥 group by

단순한 group by 절을 통해 한 컬럼의 그룹에 대한 개수를 구할 수 있다

SELECT mem_id, count(*)
FROM member
GROUP BY mem_id

🔥 count 함수 내 조건설정

count내에 조건을 설정하여 해당 조건에 따른 개수를 구할 수 있다

-- count(case when 조건 then 결과 end) as '별칭'

SELECT count(case when del=0 then mem_id end)
FROM member

🔥 count distinct 중복 제거

count ~ distinct를 활용하여 중복값을 제거한 개수를 구할 수 있다

SELECT count(distinct mem_id) as mem_cnt
FROM member




Reference

https://codingspooning.tistory.com/entry/MySQL-count-%EC%A1%B0%EA%B1%B4-%EB%B0%A9%EB%B2%95

profile
🦋개발 공부 기록🦋

0개의 댓글