我使用 codeigniter 2.1,我收到关于 SQL 版本的错误我真的需要执行这个代码..但是如何做到这一点
显示的错误:
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 'SELECT rt.srt_id, rt.pub_id, d.sd_date, CASE WHEN d.sd_doc != '' THEN d' at line 2
SET @i = 0.0; SELECT rt.srt_id, rt.pub_id, d.sd_date, CASE WHEN d.sd_doc != '' THEN d.sd_doc END sd_doc, rt.total_sales, @i + rt.total_sales AS Cumulative_Total, @i:= CASE WHEN d.sd_doc = '' THEN @i + rt.total_sales ELSE 0 END AS Increment FROM d_statistics_report_temp rt INNER JOIN d_statistics_docs d ON rt.pub_id = d.sd_pub AND rt.sal_must_pay_date = d.sd_date ORDER BY rt.pub_id, d.sd_date;
Filename: C:\xampp\htdocs\ebook\system\database\DB_driver.php
Line Number: 330
SQL查询是:
$result = $this->db->query(
"SET @i = 0.0;
SELECT rt.srt_id,
rt.pub_id,
d.sd_date,
CASE WHEN d.sd_doc != '' THEN d.sd_doc END sd_doc,
rt.total_sales,
@i + rt.total_sales AS Cumulative_Total,
@i:= CASE WHEN d.sd_doc = '' THEN @i + rt.total_sales ELSE 0 END AS Increment
FROM d_statistics_report_temp rt
INNER JOIN d_statistics_docs d
ON rt.pub_id = d.sd_pub
AND rt.sal_must_pay_date = d.sd_date
ORDER BY rt.pub_id, d.sd_date; "
);