쿼리문 질문
본문
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