假设我有以下类型的表,名为item_sales:
Item, Sales_Date, Num_Sold
--------------------------
item1, 2015-01-02, 500
item1, 2016-01-03, 350
item1, 2017-01-21, 450
item2, 2015-01-02, 750
item2, 2015-01-03, 1100
item2, 2016-01-04, 1000
item3, 2017-01-02, 200
item3, 2017-01-03, 100
item3, 2017-02-04, 100
我试图找出如何返回给定项目的所有行,如果它在过去90天内有销售。它很容易返回或找到具有分组的给定项目,但我不知道怎么说如果max(sales_date)> = date_sub(curdate(),interval 90,则给出item1和item3的所有记录天)
正确查询的输出应为:
Item, Sales_Date, Num_Sold
--------------------------
item1, 2015-01-02, 500
item1, 2016-01-03, 350
item1, 2017-01-21, 450
item3, 2017-01-02, 200
item3, 2017-01-03, 100
item3, 2017-02-04, 100