Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这张桌子:
正如您在图像中看到的,每条记录都有多个日期。我想为每条记录创建一个包含最短日期的额外列。我知道如何在 python 中做到这一点,但不知道如何在 sql 中做到这一点。我怎样才能做到这一点?
您可以使用窗口函数:
select a.*,min(a.date1) Over(Partition by a.record1) as min_date from table_name a
这将在记录级别添加一个包含最小日期的列。希望这可以帮助。