gpt4 book ai didi

mysql - MySql查询错误

转载 作者:可可西里 更新时间:2023-11-01 08:51:30 25 4
gpt4 key购买 nike

我想创建一个包含统计数据的团队列表,所以我使用了 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 ......

谁能告诉我哪里出错了?

最佳答案

你的东西与此类似,只是做了一些调整。

protected function getListQueryweqw() {
$db = JFactory::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.*";

$query->select($query_string);
$query->from('#__footsal_teams AS a');
$query->join('LEFT', '#__footsal_resaults AS w on w.id_team = a.id');


return $db->setQuery($query);
}

protected function getListQuery() {
$db = JFactory::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";

$query->select($query_string);
$query->from('#__footsal_teams AS a');

return $db->setQuery($query);
}

关于mysql - MySql查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com