trying to get the number of months

﹥>﹥吖頭↗ 提交于 2019-11-29 12:02:28

The 1054 error is because the column does not exist in the table(s) defined in the FROM clause. Additionally, the WHERE clause is not used to set a variable, or column alias -- it's for filtering rows returned.

Use DATEDIFF:

SELECT t.member_id,
       DATEDIFF(LEAST(NOW(), t.membership_dueday), t.membership_startdate) / 30
  FROM MEMBERSHIP t

The LEAST function will return the lowest of the two dates, so it will use the current date if the due date is in the future. You can use the GREATEST function if you want that reversed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!