gpt4 book ai didi

mysql - MySQL 查询返回一个空集

转载 作者:行者123 更新时间:2023-11-29 01:48:51 26 4
gpt4 key购买 nike

我有一个名为 product 的 MySQL 表,我想从中按数量降序检索日期范围内的前 3 个数据。提供我的表,

# product_id, stock_id, quantity, stock_timestamp
Product ID9, Stock ID2, 1050, 2019-03-04 07:06:37
Product ID8, Stock ID2, 950, 2019-03-04 07:06:27
Product ID7, Stock ID2, 85000, 2019-03-04 07:06:17
Product ID6, Stock ID1, 750, 2019-03-04 07:06:07
Product ID5, Stock ID1, 65000, 2019-03-04 07:05:57
Product ID4, Stock ID1, 550, 2019-03-04 07:05:47
Product ID3, Stock ID, 450, 2019-03-04 07:05:37
Product ID27, Stock ID5, 1950, 2019-02-28 07:05:17
Product ID26, Stock ID5, 1850, 2019-02-28 07:05:17
Product ID25, Stock ID5, 1750, 2019-02-28 07:05:17
Product ID24, Stock ID4, 211650, 2019-02-24 07:05:17
Product ID23, Stock ID4, 1550, 2019-02-24 07:05:17
Product ID22, Stock ID4, 1450, 2019-02-24 07:05:17

我按照提供的方式编写 SQL 查询,

SELECT * FROM StockHandler.product WHERE stock_timestamp BETWEEN  DATE("2019-03-03") AND DATE("2019-03-04")  ORDER BY quantity DESC  LIMIT 3 ;

我从返回的查询中得到一个空值。我发现 SQL 中没有错误。那么,如何正确编写呢?

最佳答案

尝试以下 - date() for stock_timestamp

SELECT * FROM StockHandler.product 
WHERE date(stock_timestamp) BETWEEN '2019-03-03' AND '2019-03-04'
ORDER BY quantity DESC LIMIT 3

关于mysql - MySQL 查询返回一个空集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54978398/

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