一个复杂的SQL语句

时间:2021-10-16 21:57:40
 1 SELECT c.*, sum(t.num) as num, b.num as total FROM np_wenjuan_choice as c
 2 left join (
 3 select content, count(id) as num
 4 from np_wenjuan_answer as a
 5 where question_id = 8
 6 group by content
 7 ) as t on t.content like concat('%',c.index,'%')
 8 left join (
 9 select question_id, count(id) as num 
10 from np_wenjuan_answer
11 where question_id = 8
12 group by question_id
13 ) as b on b.question_id = c.question_id
14 where c.question_id = 8
15 group by title
16 order by c.index