很好的一天!
我有这个sql,但不是在托管工作。在局域网上一切正常。我找不到问题所在。laravel项目sql:
$data = DB::select('
SELECT
DATE(o.created_at) as day,
count(id) as count_all,
count((SELECT id WHERE status=3)) as success,
count((SELECT id WHERE status=5)) as return_order,
count((SELECT id WHERE status=0 or status=4 or status=8)) as call_order,
count((SELECT id WHERE status=7 or status=6 or status=1)) as otkaz,
count((SELECT id WHERE status=2)) as nado_dostavit,
SUM((SELECT offer_price)) as all_price,
SUM((SELECT offer_price WHERE status=3)) as success_price,
SUM((SELECT offer_price WHERE status=5)) as return_order_price,
SUM((SELECT offer_price WHERE status=0 or status=4 or status=8)) as call_order_price,
SUM((SELECT offer_price WHERE status=7 or status=6 or status=1)) as otkaz_price,
SUM((SELECT offer_price WHERE status=2 )) as nado_dostavit_price,
(SELECT sum(s.visitors) FROM statistics as s WHERE s.offer_id='.$user_id.') as visitors
FROM
orders as o
WHERE
offer_id='.$user_id.'
AND created_at between "'.$mother_later.'" AND "'.$today.'"
GROUP BY day
ORDER BY day desc
limit 30
');
错误:
(2/2)查询异常
sqlstate[42000]:语法错误或访问冲突:1064您的sql语法有错误;检查与您的mariadb服务器版本相对应的手册,以获得正确的语法,以便在“where status=3”)附近使用success,
1条答案
按热度按时间7kqas0il1#
您的子查询都没有
FROM
子句,这就是为什么会出现语法错误。但是,您实际上不希望在这些位置使用子查询。对于COUNT
,你应该用例如。而对于
SUM
s、 你应该使用例如。总之,您的查询应该是: