Can i use num_daysopen in the second select
SELECT
DATEDIFF(DATE(NOW()), DATE(dateopened)) AS num_daysopen,
(28 - DATEDIFF(DATE(NOW()), DATE(dateopened))) as days_left
FROM table
The following does not seem to work, it would be more readable than the above if it did?
SELECT
DATEDIFF(DATE(NOW()), DATE(dateopened)) AS num_daysopen,
(28 - num_daysopen) as days_left
FROM table
A column alias isn’t available for use at the same level.
So add a derived table to add a level
See “Problems with Column Aliases” in the MySQL Docs