我通过 SQL语句统计数据select
b.sque,
a.ques_id,
case
when b.type = '1' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '2' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '3' then
a.answer
end answer
from wj_answer a, wj_ques b
where a.ques_id = b.ques_id
and a.staffno = '002030'
and a.top_id = '162'
order by a.top_id, a.ques_id;得到的数据格式如下:1 ss aa
1 ss bb
1 ss cc
2 22 dd
3 dd hh
3 dd kk
怎么写SQL把数据变成这样的结构:
1 ss aa,bb,cc
2 22 dd
3 dd hh,kk
b.sque,
a.ques_id,
case
when b.type = '1' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '2' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '3' then
a.answer
end answer
from wj_answer a, wj_ques b
where a.ques_id = b.ques_id
and a.staffno = '002030'
and a.top_id = '162'
order by a.top_id, a.ques_id;得到的数据格式如下:1 ss aa
1 ss bb
1 ss cc
2 22 dd
3 dd hh
3 dd kk
怎么写SQL把数据变成这样的结构:
1 ss aa,bb,cc
2 22 dd
3 dd hh,kk
select sque,ques_id,wm_concat(answer) answers from
(select
b.sque,
a.ques_id,
case
when b.type = '1' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '2' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '3' then
a.answer
end answer
from wj_answer a, wj_ques b
where a.ques_id = b.ques_id
and a.staffno = '002030'
and a.top_id = '162'
order by a.top_id, a.ques_id;
)
group by sque,ques_id
from (select
b.sque,
a.ques_id,
case
when b.type = '1' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '2' then
(select c.answer from wj_option c where c.answer_id = a.answer)
when b.type = '3' then a.answer end answer
from wj_answer a, wj_ques b
where a.ques_id = b.ques_id
and a.staffno = '002030'
and a.top_id = '162'
order by a.top_id, a.ques_id)
group by sque,ques_id