gpt4 book ai didi

mysql - 选择时间之间,填写空时间

转载 作者:行者123 更新时间:2023-11-29 13:44:12 25 4
gpt4 key购买 nike

我这里有一个数据库

| TIME | STOCK
|9:00 |24
|12:00 | 15

我想显示从现在早上 6 点到明天凌晨 4 点的时间

我想把它放在一个mysql查询中,我将在与我的数据库不相似的特定时间放置null

像这样

ID   | STOCK
6:00 |NULL
7:00 |NULL
8:00 |NULL
9:00 |24
10:00|NULL
11:00|NULL
12:00|15

等等...

有没有人知道解决办法。预先感谢您。

最佳答案

一种方法是您可以为您需要的所有时隙创建临时表,左连接就可以解决问题。

库存表:

create table stock (TIME varchar(5), STOCK int(2));
insert into stock values
('9:00',24),
('12:00',15);

时序表(需要是临时的)

  create TEMPORARY table timings (timings varchar(5));
insert into 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');

您的选择查询将是

select timings,STOCK from timings t left join
stock s on t.timings = s.TIME;

请参阅fiddle

关于mysql - 选择时间之间,填写空时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17650435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com