我有一个SQL where子句的问题,希望你能帮我。我正在尝试过滤我的产品数据库查询的结果,以不检索库存接收日期大于01/10/19的指定产品类型,如果产品类型在数据库中的另一个日期小于01/10/19,那么它也应该包括在结果中。
在下面的示例中,我不希望SQL显示产品类型为"446“且产品接收日期为>= 01/10/2019的任何产品。所以批号为"AE0152“的奶制品我不想被包括在结果中,但是批号为"AE0142”的奶制品我想。
我希望这是有意义的。我尝试了几种不同的组合,但似乎都不起作用。
任何帮助都将不胜感激。谢谢
Product No: Product Description: Product Type: Product received date: Batch Number:
00001441 Milk 446 30/09/2019 AE0142
00001441 Eggs 446 15/10/2019 AE0151
00001441 Milk 446 04/10/2019 AE0152
00001441 Flour 450 08/10/2019 AE0201
00001441 Sugar 450 08/10/2019 AE0201
00001441 800g White loaf 500 14/10/2019 AE0232发布于 2019-11-13 19:28:25
你可以做一些类似的事情:
SELECT *
FROM products
WHERE ProductId <> 446 -- Get all products that are not "446"
OR (ProductId = 446 AND rec_date < DATE '2019-10-01') -- Get certain "446" products已更新
SELECT *
FROM products
WHERE (
prod_type <> 446 OR -- get all non-446 products
rec_date < DATE '2019-10-01' -- Get all products that meet date restriction
)这将阻塞prod_type = 446 AND date >= '2019-10-01'为true的行,我认为这就是您所要求的。
发布于 2019-11-13 19:44:04
你可以这样做:
select * from table_name where product_received_date < '2019-10-01'已更新
select * from table_name where product_received_date < '2019-10-01' || product_type = 446根据数据库更改日期格式,如Y-m-d或d-m-Y。如果您的product_received_date是string类型,那么在where子句中以相同的格式指定日期。
发布于 2019-11-13 19:58:46
SELECT * FROM products WHERE (ProductId <> 446 AND rec_date > DATE '2019-10-01')
https://stackoverflow.com/questions/58836047
复制相似问题