我想创建一个包含统计信息的团队列表,所以我使用了 2 个函数,每个函数包含 2 个不同的数据库查询:
protected function getListQueryweqw() {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$query_string = '';
$query_string .= 'a.*, COUNT(w.id) AS played_games, SUM(w.team_goals) AS goals,';
$query_string .= "COUNT(w.match_status = 'draw') AS draw,";
$query_string .= "COUNT(w.match_status = 'win' ) AS win,";
$query_string .= "COUNT(w.match_status = 'lose') AS lose,";
$query_string .= "SUM(w.team_points) AS points, SUM(w.goal_lost) AS goal_lost, w.*";
// Select the required fields from the table.
$query->select($query_string);
$query->from('`#__footsal_teams` AS a');
$query->join('LEFT', '`#__footsal_resaults` AS w on w.id_team = a.id');
return $query;
}
protected function getListQuery() {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$query_string = '';
$query_string .= 'a.*, COUNT(SELECT id FROM `#__footsal_resaults` WHERE id_team = a.id) AS played_games, ';
$query_string .= "SUM(SELECT team_goals FROM `#__footsal_resaults` WHERE id_team = a.id) AS goals,";
$query_string .= "COUNT(SELECT id FROM `#__footsal_resaults` WHERE match_status = 'draw') AS draw,";
$query_string .= "COUNT(SELECT id FROM `#__footsal_resaults` WHERE match_status = 'win') AS win,";
$query_string .= "COUNT(SELECT id FROM `#__footsal_resaults` WHERE match_status = 'lose') AS lose,";
$query_string .= "SUM(SELECT team_points FROM `#__footsal_resaults` WHERE id_team = a.id) AS points, SUM(SELECT goal_lost FROM `#__footsal_resaults` WHERE id_team = a.id) AS goal_lost";
// Select the required fields from the table.
$query->select($query_string);
$query->from('`#__footsal_teams` AS a');
return $query;
}
然而,这两个查询似乎都不起作用,我得到的错误的开始是:
JDatabaseMySQLi::query: 1064 ......
有人可以告诉我我哪里出错了吗?