| 候選人 | 位置 |
|---|---|
| 約翰 | 公投 |
| 標記 | 公投 |
| 蘇菲亞 | 總理 |
| 約翰 | 公投 |
| 約翰 | 公投 |
| 蘇菲亞 | 總理 |
| 標記 | 公投 |
| 蘇菲亞 | 總理 |
| 安娜 | 總理 |
| 約翰 | 公投 |
嗨,伙計們,T 需要此查詢的幫助來計算結果,我將是什么輸出:
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) 聚合作為視窗函式
感謝幫助
uj5u.com熱心網友回復:
我認為您需要查看GROUP BY,例如:
SELECT COUNT(*) AS `total`, `candidate`, `position`
FROM `votes`
GROUP BY `candidate`, `position`
(反勾號,以防萬一……)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/505798.html
上一篇:PHP中沒有互聯網的CURL請求
