[英]How to count rows in MYSQL table with multiple column criteria?
I have a table to football results in a mysql table and want to count how many games have been played by season and game type. 我在mysql表中有一个足球统计表,想按季节和游戏类型计算出多少场比赛。
For example the table looks like this 例如,表格看起来像这样
+---------------+-------------+----------+
| Type | Season | Goals |
+---------------+-------------+----------+
| Club | 11 | 4 |
+---------------+-------------+----------+
|International | 12 | 5 |
+---------------+-------------+----------+
| Club | 12 | 0 |
+---------------+-------------+----------+
What I want to do is total the number of club games played in season 12 so that would result in 1. 我想要做的是在第12赛季参加俱乐部比赛的总数,这样就得出1。
the current MYSQL code I have is 我当前的MYSQL代码是
"SELECT COUNT * FROM table WHERE season='12' AND type='club'"
and that isn't working as I think I am using the wrong function. 这是行不通的,因为我认为我使用了错误的功能。 What is the correct function for the desired output? 所需输出的正确功能是什么?
try this 尝试这个
SELECT COUNT(*) total FROM `<tablename>` WHERE season=12 AND type='club';
make sure your connection established: 确保建立连接:
$sql = "SELECT COUNT(*) total FROM cristiano WHERE season=12 AND which='club'"
if ($result=mysql_query($sql)) {
while($row=mysql_fetch_row($result)) {
echo $row['total'];
}
} else {
echo "Error" . mysql_error();
}
我认为您可以使用count()函数。请在表WHERE season = '12'AND type ='club'中找到以下查询SELECT COUNT(*);
here Table name is 'table' and type-column name is 'type' - These both words 'table' and 'type' are reserved words, so while executing the query , write the query as: 这里表名是“表”,类型列名是“类型”-这两个词“表”和“类型”都是保留词,因此在执行查询时,将查询写为:
SELECT COUNT(*) FROM `table` WHERE `season`=12 AND `type`='club';
use ` sign as used in above code-line. 使用上面代码行中使用的`符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.