[英]Different select query based on the day of week? - MySQL
是否可以在一周的每一天执行不同的选择查询。 我目前有以下几列:id,station_name,week_type和service。
week_type是一个enom值,具有以下选项:'Mon-Thur','Fri','Sat','Sun','Special'。
服务列仅具有一天中的时间的varchar值。 它需要应用,因为该服务根据week_type在每周的时间表上运行相同。
+-----------------------------------+------------+-----------+-----------+
| id |station_name| week_type | service |
+-----------------------------------+------------+-----------+-----------+
| 1 | Station1 | Mon-Thur | 08:15:00 |
| | | | |
| 2 | Station2 | Sat | 10:15:00 |
+-----------------------------------+------------+-----------+-----------+
如上表所示,当我所在时区中的星期六是星期几,并且等于week_type时,它应该只显示星期六的行。 其他列等等。
任何帮助将不胜感激,因为我是SQL新手。
我认为您确实需要在桌子上锻炼。 你为什么不规范你的表。
station_services
id|station_name
station_working_days
id|station_id|weekday_id|working_hours
如果您不希望将工作日作为单独的表格,则可以将1硬编码为星期日,而将星期六硬编码为7
station_working_days
id|station_id|weekday|working_hours
通过规范化,您将来也将获得所有的灵活性。
如果各站始终都具有相同的工作时间,请使用下表标准化来为您提供帮助。
station_services
id|station_name|working_hours
station_working_days
id|station_id|weekday_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.