执行排名查询时mysql语法错误
我想执行排名查询,但我不确定正确的语法是什么 这是我的查询:
static public function sortranks(){
global $db;
$sql ="TRUNCATE TABLE `ranking`";
$db->query($sql);
$sql = "INSERT INTO `ranking` (`user_id`) VALUES
( SELECT `employe_id` FROM `rates_employe` WHERE `status` = '0' ORDER BY rawpoint DESC ) ";
$db->query($sql);
$sql = "UPDATE rates_employe , ranking SET rates_employe.rank = ranking.rank WHERE
rates_employe.employe_id = ranking.user_id ";
$db->query($sql);
echo 'ok';
exit;
}
当我运行此查询时,我不断收到语法错误
数据库查询失败:您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 在 'SELECT
employe_id
FROMrates_employe
WHERE 附近使用的语法status
= '0' ORDER BY rawpoint ' at line 2
i want to perform a ranking query but i'm not sure what is the right syntax
here is my query:
static public function sortranks(){
global $db;
$sql ="TRUNCATE TABLE `ranking`";
$db->query($sql);
$sql = "INSERT INTO `ranking` (`user_id`) VALUES
( SELECT `employe_id` FROM `rates_employe` WHERE `status` = '0' ORDER BY rawpoint DESC ) ";
$db->query($sql);
$sql = "UPDATE rates_employe , ranking SET rates_employe.rank = ranking.rank WHERE
rates_employe.employe_id = ranking.user_id ";
$db->query($sql);
echo 'ok';
exit;
}
i keep getting syntax error when i run this query
Database query failed: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'SELECTemploye_id
FROMrates_employe
WHEREstatus
= '0' ORDER BY rawpoint ' at line 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该一项一项地执行查询,而不是将它们连接在一起。
使用简单的赋值更改
.=
字符串连接,并在分配每个查询后执行它。如:同时从查询中删除VALUES:
抱歉,如果我听起来很迂腐,但是是英语
Employee
在单词末尾拼写有两个e
。You should execute the queries one by one, instead of joining them together.
Change the
.=
string concatenation with a simple assignment, and after assigning each query, execute it. Such as:Also remove VALUES from the query:
Sorry if I sound pedantic, but in English
Employee
is spelt with twoe
at the end of the word.尝试分别运行每个查询:
Try running each queries separately: