I am building the following Query but am having syntax problems:
SELECT FORMAT(yrs_served * 365, 0) AS days_served,
ADDDATE(date_comm, INTERVAL days_served DAY(DATE_FORMAT(CONCAT_WS('-', yr_comm, mth_comm, day_comm), %Y-%m-%d) AS date_comm) AS left_office
FROM prime_minister JOIN ministry
;
As can been seen, I am first trying to CONCAT_WS three values into a date, then format it as a date with DATE_FORMAT, so that I can then use ADDDATE to add a number of days to this date.
Please advise where I am going wrong, thank you!
you cannot use
ALIASon the same level it has been define.if you wan’t to use it, you just wrap it in a subquery, eg
DATE_ADD)