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
子句中使用。