[英]count occurrences in mysql
resp_id visitorID surveyID questionID response answer userID
43 777 163 736 MS 0 1
42 777 163 736 Rohit 1 1
41 777 163 736 Virat 1 1
40 776 163 736 MS 1 1
39 776 163 736 Rohit 3 1
38 776 163 736 Virat 1 1
37 775 163 736 MS 0 1
36 775 163 736 Rohit 1 1
35 775 163 736 Virat 2 1
34 774 163 736 MS 2 1
33 774 163 736 Rohit 3 1
32 774 163 736 Virat 1 1
我想對響應中的表中“答案”字段的每個值進行計數
我已經嘗試過但沒有得到
SELECT count(answer) as answer_cnt
FROM `sg_finished_surveys`
WHERE resopnse = $q GROUP BY `answer`
其中$q
等於唯一響應值。
您要使用一個計數和一個group by語句來獲取每種答案的數量:
SELECT
count(*) as answer_cnt,
`answer`
FROM
`sg_finished_surveys`
WHERE
response = '$q'
GROUP BY
`answer`
這將計算每個答案的實例數量,並為您提供實際答案。
您的where
子句中也有錯字(resopnse!= response)。
您可能還需要檢查一下我發布的“ 問答”,其中涵蓋了此類查詢以及更多內容。
使用visitorID分組,即
SELECT count(answer) as answer_cnt FROM `sg_finished_surveys`
WHERE resopnse = $q group by visiterID
$q
必須用單引號引起來。
SELECT count(*) as answer_cnt
FROM `sg_finished_surveys`
WHERE resopnse = '$q' GROUP BY `answer`
SELECT COUNT(answer)
FROM `sg_finished_surveys`
WHERE respondence = '".$q."'
GROUP BY answer
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.