sql - how to count multiple value in count function -
table
id q1 q2 q3 q4 q5 ----------------------------------- 1 v.good fair fair ----------------------------------- 2 v.good fair fair
i want answer this
---------------------- status q1 q2 q3 q4 q5 ---------------------- v.good 4 3 2 4 3 ---------------------- 4 5 6 7 8 ---------------------- fair 5 7 6 3 9 ----------------------
can 1 me in problem feel stuck thank in advance
i assuming sample data incomplete expected output doesn't seem have of in terms of counts provided.
if case guess @ interpreting want is:
select 'v.good' status, sum(case when q1 = 'v.good' 1 end) q1, sum(case when q2 = 'v.good' 1 end) q2, sum(case when q3 = 'v.good' 1 end) q3, sum(case when q4 = 'v.good' 1 end) q4, sum(case when q5 = 'v.good' 1 end) q5 tbl union select 'good', sum(case when q1 = 'good' 1 end) q1, sum(case when q2 = 'good' 1 end) q2, sum(case when q3 = 'good' 1 end) q3, sum(case when q4 = 'good' 1 end) q4, sum(case when q5 = 'good' 1 end) q5 tbl union select 'fair', sum(case when q1 = 'fair' 1 end) q1, sum(case when q2 = 'fair' 1 end) q2, sum(case when q3 = 'fair' 1 end) q3, sum(case when q4 = 'fair' 1 end) q4, sum(case when q5 = 'fair' 1 end) q5 tbl
Comments
Post a Comment