每个条目的最大日期

Max Date for each entry

我是 SQL 的新手,我正在尝试查询有很多重复项的内容,所以我得到了很多日期,但我只想要每个条目中的 1 个并且我正在为如何做到这一点而苦苦挣扎。

这是我所拥有的示例查询,但我不确定如何从这里获得我正在寻找的结果。

select 
    product_id,
    max(date_ordered)
    from products

更新:我也试过分组依据,但由于有多个日期,列表中仍然有重复的产品。我如何只列出 1 个最近订购日期的产品?

更新:Group by 终于成功了,感谢那些建议的人。用户错误。

你必须使用 group by ,你有这里的文档:https://sql.sh/cours/group-by

select product_id,max(date_ordered)
from products
group by product_id

I tried Group by date ordered and products, it still has duplicate products in the list.

product_id 列(而不是 date_ordered 列)使用 GROUP BY

SELECT product_id,
       max(date_ordered)
FROM   products
GROUP BY product_id;