我有mysql查询,它似乎工作,但不会从付款表返回值。 怎么了?
SELECT members.id, members.name, members.lastname
FROM members
JOIN (SELECT payments.id, payments.user_id, payments.begin_date,
MAX(payments.finish_date) AS finish_date, payments.price
FROM payments
GROUP BY payments.user_id)
AS payments
WHERE members.id=payments.user_id AND payments.finish_date>=CURDATE()
ORDER BY payments.finish_date ASC, payments.id ASC`
我使用:
echo stripslashes($wiersz['begin_date']);
返回行数据。
答案 0 :(得分:0)
finish_date只是一个日期还是有小时,分钟和秒?你可以尝试这个并格式化日期
WHERE members.id=payments.user_id AND DATE(payments.finish_date) >= CURDATE()
ORDER BY DATE(payments.finish_date) ASC, payments.id ASC
答案 1 :(得分:0)
您可能需要注意,您没有在主查询中选择begin_date字段:
SELECT members.id, members.name, members.lastname FROM ...
尝试使用
SELECT members.id, members.name, members.lastname, begin_date FROM ...
安德烈