gpt4 book ai didi

mysql - 尝试查找酒吧营业时间内发生的账单 - Mysql

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

我正在尝试查找酒吧营业时间内发生的所有账单。示例:

|bills table           |      |bars table                 |
|billID |time |name | |barName | barOpHr | barClHr|
|1 |22:00 |bar1 | |bar1 | 20:00 | 03:00 |
|2 |15:00 |bar2 | |bar2 | 19:00 | 02:00 |
|3 |23:35 |bar3 | |bar3 | 22:00 | 03:00 |

努力实现:

|bills table           |      
|billID |time |name |
|1 |22:00 |bar1 |
|3 |23:35 |bar3 |

我的代码如下所示:

select distinct b.billID from bills as b
inner join bars as s where s.name = b.bar
and time_to_sec(time(b.time)) - time_to_sec(time(s.closing)) > '0'
and time_to_sec(time(b.time)) - time_to_sec(time(s.opening)) > '0'

它没有返回正确的行数,有人可以告诉我我的错误是什么吗?谢谢。

最佳答案

尝试以下:

select distinct b.billID, b.time, b.name
from bills as b inner join bars as s on s.name = b.barName
where (
time_to_sec(time(b.time)) - time_to_sec(time(s.barOpHr)) > '0'
and time_to_sec(time(b.time)) - time_to_sec(time(s.barClHr)) > '0'
)

请考虑使用JOIN。此外,我建议您使用 ID 作为 bars 表中的主键,而不是名称。

关于mysql - 尝试查找酒吧营业时间内发生的账单 - Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53035255/

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