-1
"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得票?

4

4 回答 4

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)
于 2013-05-18T04:48:51.563 回答
1

检查SQLFiddle

SELECT *
FROM Votestable v
WHERE v.votes > (SELECT
                   votes
                 FROM Votestable v1
                 WHERE v1.id = v.parent) * 0.1
于 2013-05-18T06:08:33.460 回答
0

尝试这个 :-

select id from table where type =10 and votes>=(votes/100)*10;
于 2013-05-18T05:00:29.037 回答
0

既然你提到总票数为 105,

select * , ((votes * 100) / 105) as percent
from votesTable
where ((votes * 100) / 105) > 10.0 and type=10 and parent = 4177
于 2013-05-18T06:05:01.247 回答