我有一个php页面,它必须显示“国家”的“总分”,例如
假设我们有以下..。
现在我想要显示的是SUA的总分,它是30。
SELECT score,country,COUNT(*) FROM users WHERE country GROUP BY score发布于 2019-02-15 16:24:03
您可以使用总和函数。
select sum(score) as 'total', country
from users
group by country这将返回如下内容:
+-------+---------+
| total | country |
+-------+---------+
| 30 | SUA |
| 7 | Canada |
+-------+---------+还可以使用where子句按国家筛选查询:
select sum(score) as 'total', country
from users
where country = 'Canada'这将提供以下内容:
+-------+---------+
| total | country |
+-------+---------+
| 7 | Canada |
+-------+---------+发布于 2019-02-15 16:22:52
提取数据后,用每个分数创建单个对象或节点,然后循环遍历它们,将分数与"SUA“相加。
发布于 2019-02-15 16:24:44
如果分数为整型/浮点/双倍,则必须这样做:
SELECT SUM(score) as total, country from users GROUP BY score;https://stackoverflow.com/questions/54713211
复制相似问题