if Meituan wants to inquire about restaurants open at the current time, how do you deal with
store business schedule
store ID start time and end time (a store can have multiple records)
I think the new table is good
does not know the actual scene, the description is very vague, the demand you said is only the need to store business hours, of course, a new table to save. Start time and end time are stored separately to facilitate query, and your requirements should be dated.
I understand your demand is
A shop opens at 9:00, ends at 13:00, starts at 00:00 and ends at 22:00.
then the database design should be:
A store usually has no more than three business hours, so there can be three fields to store the time period
table
id, name, duration_id1, duration_id2, duration_id3
then the table design for the time period:
table
id, start_time, end_time
the duration_id of the store table is the foreign key of the time period table.
the time period table is equivalent to reference data, while the data of the store table is changed.
one-to-many time in stores / supermarkets.
you can build tables and json as you say.
it is convenient to build tables, but it is inconvenient to write an extra sql,
json to query by time.
I like to build a table
suggest building a new table. In addition to querying the current restaurant requirements mentioned above, there is also a unified modification of all business hours. Different business hours in spring and autumn, working days and weekends make it better to build a new table.
at present, my practice is to store json, for the time period in DB. Json takes an object List collection that contains Integer startTime and Integer endTime, and then takes it out and converts it to list. As for time saving is minutes, for example: 6:30 in the morning is 6 * 60 + 30 = 390 also checked for non-overlapping save failures.