로딩
요청 처리 중입니다...

mysql 조건문이 들어가는 쿼리 CASE WHEN THEN ELSE END

 mysql 조건문이 들어가는 쿼리 CASE WHEN THEN ELSE END

funding 테이블에서 상태가 각각 다른 펀딩의 COUNT를 SELECT 하려 한다.이런식으로 조건을 달아줄 수 있다. SELECT COUNT(*) totalFundingCount , COUNT(CASE when fdStatus="모집중" OR fdStatus="결제모집중" then 1 end) totalRecruitingFundingCount , COUNT(CASE when fdStatus="개설요청" then 1 end) totalRequestFundingCount , COUNT(CASE when fdStatus="진행중" then 1 end) totalProceedingFundingCount FROM funding then 1 이라고 해줬다. (1,2,3 상관없다.

그저 하나의 문자로써의 1이기 때문. 합산하는 경우랑은 다르다 )then 은 앞의 when 조건이 맞다면 값을 1로 해준다 then null 로 한다면COUNT 결과가 0 이 된다.즉 COUNT ..........