Mysql 获得不同的电流&;来自列类型varchar()的未来周数和年份
我有一个每周预订的专栏,格式为WEEKNO-YEAR,例如Mysql 获得不同的电流&;来自列类型varchar()的未来周数和年份,mysql,sql,mariadb,Mysql,Sql,Mariadb,我有一个每周预订的专栏,格式为WEEKNO-YEAR,例如20-2018。该列还包含未来几周01-2019或20-2019等 我需要当前和未来几周的明确列表,所以我使用下面的查询,但它只返回我今年的数据。有没有办法让未来的几周都过得愉快 SELECT DISTINCT(booking_week) as booking_weeks_list from bookings where booking_week >= date('W-Y', time()) 我确实有一列有预订日期的时间戳,但
20-2018
。该列还包含未来几周01-2019
或20-2019
等
我需要当前和未来几周的明确列表,所以我使用下面的查询,但它只返回我今年的数据。有没有办法让未来的几周都过得愉快
SELECT DISTINCT(booking_week) as booking_weeks_list
from bookings
where booking_week >= date('W-Y', time())
我确实有一列有预订日期的时间戳,但我不知道这是否有帮助?让我假设
date('W-Y',time())
返回当前的周/年。我不知道这是从哪个数据库来的,但基本上你想做:
select distinct booking_week as booking_weeks_list
from bookings
where right(booking_week, 4) || '-' || left(booking_week, 2) >= date('Y-W', time())
有关解决方案的说明:
- 并非所有数据库都支持
和left()
<代码>子字符串()/right()
可以替代使用子字符串()
是ANSI标准字符串连接运算符。这也可能因数据库而异|
- 我不认识日期('Y-W',time()),但假设它是正确的
DATE()
。