I am trying to get the maximum mysql select value, but want to have it null / empty / 0 if there is one row not containing a timestamp.
Statistics table (simple):
ID CLIENT ORDER_DATE CANCEL_DATE 1 5 1213567200 2 5 1213567200 3 6 1210629600 1281736799 4 6 1210629600 1281736799 5 7 1201042800 1248386399 6 7 1201042800 7 8 1205449200 1271282399
Now I want to get the date of the lowest order (no problem, since it is never empty), and the maximum cancellation date. If the customer has already canceled their subscription, the cancellation date will be filled out, but if it is still active, the cancellation date is completely absent.
Query:
SELECT ID, min(ORDER_DATE) AS OD, max(CANCEL_DATE) AS CD FROM stats GROUP BY CLIENT
Return:
ID OD CD 5 1213567200 // fine 6 1210629600 1281736799 // fine 7 1201042800 1248386399 // Should be empty 8 1205449200 1271282399 // fine
I cannot figure out how to return empty / 0 / NULL if there are one (or several) empty numbers for the client. Also tried with NULL fields.
Thanks for any hint.
source share