一次查询中的多个计数
这个查询不起作用。有人可以帮我吗?
$query = "SELECT
COUNT(WHERE Name='george') AS george_total,
COUNT(WHERE Name='michael') AS michael_total,
COUNT(WHERE Name='mike') AS mike_total
FROM users WHERE Banned IS NOT '1' AND Active='yes' AND Logins>1 AND Registered_to_forum='1'";
$row=mysql_fetch_array($result);
echo "
We found $row['george_total'] people with the name 'George' in our database,
$row['michael_total'] with the name Michael
and $row['mike_total'] with the name Mike.
";
This query doesn't work. Can someone help me please?
$query = "SELECT
COUNT(WHERE Name='george') AS george_total,
COUNT(WHERE Name='michael') AS michael_total,
COUNT(WHERE Name='mike') AS mike_total
FROM users WHERE Banned IS NOT '1' AND Active='yes' AND Logins>1 AND Registered_to_forum='1'";
$row=mysql_fetch_array($result);
echo "
We found $row['george_total'] people with the name 'George' in our database,
$row['michael_total'] with the name Michael
and $row['mike_total'] with the name Mike.
";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
CASE
语句以及COUNT
或SUM
。COUNT
版本如下。COUNT
仅计算NOT NULL
值,因此您可以使用任何非空列或常量而不是 1。SUM
版本为You can use a
CASE
statement and eitherCOUNT
orSUM
.The
COUNT
version is below.COUNT
only countsNOT NULL
values so you can use any Non Null column or constant instead of 1.The
SUM
version is