[英]sql query to count distinct
候選人 | position |
---|---|
約翰 | 公投 |
標記 | 公投 |
蘇菲亞 | 總理 |
約翰 | 公投 |
約翰 | 公投 |
蘇菲亞 | 總理 |
標記 | 公投 |
蘇菲亞 | 總理 |
安娜 | 總理 |
約翰 | 公投 |
嗨,伙計們,T 需要此查詢的幫助來計算結果,我將是什么 output:
john, for the referdum, has 4 votes
mark, for the referdum has 2 votes
sofia, for the premier has 3 votes
anna, for the premier has 1 votes
SELECT DISTINCT
candidate,
position,
count(DISTINCT candidate) over (order by position) AS votes_received
from votes;
這是我的查詢,但說:
此版本的 MariaDB 尚不支持 'COUNT (DISTINCT) 聚合為 window function
感謝幫助
我認為您需要查看GROUP BY ,例如:
SELECT COUNT(*) AS `total`, `candidate`, `position`
FROM `votes`
GROUP BY `candidate`, `position`
(反勾號,以防萬一……)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.