我有一个php页面,例如必须显示"COUNTRY"的"总分"
假设我们有以下......
现在我想要的是显示SUA的总分数,例如30分
SELECT score,country,COUNT(*) FROM users WHERE country GROUP BY score
Run Code Online (Sandbox Code Playgroud)
您可以使用sum函数.
select sum(score) as 'total', country
from users
group by country
Run Code Online (Sandbox Code Playgroud)
这将返回如下内容:
+-------+---------+
| total | country |
+-------+---------+
| 30 | SUA |
| 7 | Canada |
+-------+---------+
Run Code Online (Sandbox Code Playgroud)
您还可以使用where子句按国家/地区过滤掉您的查询:
select sum(score) as 'total', country
from users
where country = 'Canada'
Run Code Online (Sandbox Code Playgroud)
这将给出以下内容:
+-------+---------+
| total | country |
+-------+---------+
| 7 | Canada |
+-------+---------+
Run Code Online (Sandbox Code Playgroud)