"id" "type" "parent" "country" "votes" "perCent"
"4177" "3" "4176" "US" "105" "0"// total of all the below
"4178" "10" "4177" "US" "15" "0"
"4179" "10" "4177" "US" "50" "0"
"4180" "10" "4177" "US" "25" "0"
"4181" "10" "4177" "US" "5" "0"
"4182" "10" "4177" "US" "10" "0"
在MySQL中,是否可以选择拥有10%选票的行。在此处,id = 4177
拥有该类别的总票数。基于此,是否可以选择type = 10 and parent = 4177
和哪些10% or more
投票的人?
答案 0 :(得分:1)
SELECT
*
FROM myTable v
WHERE
v.Type = 10
AND 0.1 < v.Votes / (SELECT MAX(m.votes) FROM myTable m WHERE m.Type = 3 AND m.Id = t.Parent)
答案 1 :(得分:1)
SELECT *
FROM Votestable v
WHERE v.votes > (SELECT
votes
FROM Votestable v1
WHERE v1.id = v.parent) * 0.1
答案 2 :(得分:0)
试试这个: -
select id from table where type =10 and votes>=(votes/100)*10;
答案 3 :(得分:0)
由于你提到了105票,
select * , ((votes * 100) / 105) as percent
from votesTable
where ((votes * 100) / 105) > 10.0 and type=10 and parent = 4177