쿼리문 질문

쿼리문 질문

QA

쿼리문 질문

본문

wr_6 여분필드에 

'사과'

'배'

 

값이름 그대로 두가지 값이 저장됩니다.

 

사과와 배의 각각 총개수를 뽑고 싶은데 어떻게 해야 하나요.?

(이름 부분은 wr_4 필드를 이용했습니다)

 

이름 사과
홍길동 200 300
홍길서 150 250

 

이 질문에 댓글 쓰기 :

답변 2

select wr_name

        , sum(if(instr(wr_4, '사과') >=0, 1, 0)) apple_count

        , sum(if(instr(wr_4, '배') >=0, 1, 0)) peach_count

from g5_write_boardname and wr_is_comment=0

  and wr_datetime between '2018-01-01 00:00:00' and  '2018-01-07 23:59:59'

group by mb_id

 

select wr_4, (select count(a.wr_1)
                    from g5_write_table a
                    where a.wr_1 = '사과'
                        and a.wr_name = c.wr_name) cnt
                    , 
                    (select count(a.wr_1)
                    from g5_write_table a
                    where a.wr_1 = '배'
                        and a.wr_name = c.wr_name) cnt
from g5_write_table c

where wr_4 <> ''
group by wr_4

답변을 작성하시기 전에 로그인 해주세요.
전체 123,128 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT