For the artists currently in bands, the value is null. How can I calculate how long they have been in the band if the value is null using mySQL?
I was thinking of doing something like this, which only works for artists who have left a band.
truncate(datediff(m.leave_date, m.joined_date)/365, 0)
Advertisement
Answer
I haven’t done SQL for a while so please bear with me.
Basically, you want to coalesce your leave date to “now” if it’s null (current member). See https://www.w3schools.com/sql/func_mysql_ifnull.asp
truncate(datediff( ifnull(m.leave_date, now()), m.joined_date)/365, 0)