简体   繁体   English

mysqli_query 中的语法错误

[英]Syntax Error in mysqli_query

$db_query = mysqli_query($link, "Select Name,  BriefDescription, SUM(Runs) as Runs
                                FROM BaseTable
                                WHERE  RunDate >= DATE_ADD(day, -$dataRange, getdate() ) AND RunDate <= getdate() 
                                GROUP BY Name,  BreifDescription");

The error message I am getting is我收到的错误消息是

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 '-30, getdate() ) AND RunDate <= getdate() GROU' at line 3

and I am confused as to where my error is我很困惑我的错误在哪里

$db_query = mysqli_query($link, "Select Name,  BriefDescription, SUM(Runs) as Runs
                                FROM BaseTable
                                WHERE  RunDate >= (CURDATE() - INTERVAL $dataRange day) AND RunDate <= CURDATE()
                                GROUP BY Name,  BreifDescription");

Changing to use CURDATE() and interval seemed to work around this issue.更改为使用 CURDATE() 和 interval 似乎可以解决此问题。

DATE_ADD only takes 2 parameters, you have 3. DATE_ADD 只需要 2 个参数,你有 3 个。

date_add(day, offset) date_add(天,偏移量)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM