我有发票表,credit_memo表和付款表。我无法从发票到期日,付款发放日期或贷记凭证发放日期返回最长日期。
SELECT
T1.b2b_id,
MAX(T1.due_date) | coalesce(T3.issue_date, '1000-01-01') |
coalesce(T4.issue_date, '10001-01-01') AS endDate
FROM t_invoice AS T1
LEFT JOIN t_linked_transaction AS T2 ON T2.invoice_uid = T1.uid
LEFT JOIN t_payment AS T3 ON T3.uid = T2.payment_uid
LEFT JOIN t_credit_memo AS T4 ON T4.uid = t2.credit_memo_uid
MAX查询返回20150301009885。
正确的日期是2015-03-01 00:00:00,如果我用DATE(MAX(...))包装MAX查询,则返回NULL
感谢您的帮助