mysql - 为什么这样查询会报错
本文介绍了mysql - 为什么这样查询会报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
SELECT
o.user_id,o.audittime,
o.shop_name,
(
SELECT
count(pay_count)
FROM
ot_payment_history AS p
WHERE
o.user_id = p.pay_user_id
AND o.order_id = p.pay_order_id
) AS f
FROM
ot_mall_order AS o
WHERE
and (((1462531924 - (o.audittime + (f * 60*60*24*30))) / 60*60*24) - 30 ) > 0
错误: [Err] 1064 - 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 'and (((1462531924 - (o.audittime + (f 60602430))) / 606024) - 30 ) > 0' at line 16
去掉f * 能正确返回数据
order order_id表 去关联 P表的pay_order_id , 统计Pay表 pay_count 相加 然后用 order 表的 audittime 减去 pay_count相加的值
order 表
pay 表
这条sql怎么写
解决方案
where
和and
不能连在一起吧?f
是字段别名。字段别名只能在order by
中使用,不能在where
子句中使用。
这篇关于mysql - 为什么这样查询会报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文