i have database here
| time | stock |9:00 |24 |12:00 | 15
i want display time 6am until 4am tomorrow
i want put in mysql query put null in specific time not similar in database
like this
id | stock 6:00 |null 7:00 |null 8:00 |null 9:00 |24 10:00|null 11:00|null 12:00|15
and on...
is there body knows solution . thank in advance.
one way can create temporary table time-slots need , left join trick.
stock table:
create table stock (time varchar(5), stock int(2)); insert stock values ('9:00',24), ('12:00',15);
timings table (need temporary)
create temporary table timings (timings varchar(5)); insert timings values ('6:00'), ('7:00'), ('8:00'), ('9:00'), ('10:00'), ('11:00'), ('12:00'), ('13:00'), ('14:00'), ('15:00'), ('16:00'), ('17:00'), ('18:00');
and select query
select timings,stock timings t left join stock s on t.timings = s.time;
see fiddle
Comments
Post a Comment