如何找到最早的时间添加了一个外键

发布于 2025-01-31 04:16:28 字数 610 浏览 1 评论 0原文

我的问题是我有一个外国钥匙列表和添加的日期,所以

+----------------+---------------+
|  Foreign Key   |  Date         |
+----------------+---------------+
|  4             |  2022-05-25   |
|  5             |  2022-05-30   |
|  4             |  2022-05-30   |
+----------------+---------------+

我需要的是只显示最早的日期,所以我不希望第二个“ 4”,因为它是在此之后创建的第一个。有什么方法可以显示每个密钥的最早日期?像这样:

+----------------+---------------+
|  Foreign Key   |  Date         |
+----------------+---------------+
|  4             |  2022-05-25   |
|  5             |  2022-05-30   |
+----------------+---------------+

My problem is that I have a list of foreign keys and the date that they were added, as so:

+----------------+---------------+
|  Foreign Key   |  Date         |
+----------------+---------------+
|  4             |  2022-05-25   |
|  5             |  2022-05-30   |
|  4             |  2022-05-30   |
+----------------+---------------+

What I require is that only the earliest date is displayed, so I do not want that second '4' as it was created after the first one. Is there a way that I can display just the earliest dates of each key? Like this:

+----------------+---------------+
|  Foreign Key   |  Date         |
+----------------+---------------+
|  4             |  2022-05-25   |
|  5             |  2022-05-30   |
+----------------+---------------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心病无药医 2025-02-07 04:16:28

尝试使用min()功能

SELECT [Foreign Key]
      ,MIN(Date) as [Date]
FROM YourTable
GROUP BY [Foreign Key]

Try using MIN() function

SELECT [Foreign Key]
      ,MIN(Date) as [Date]
FROM YourTable
GROUP BY [Foreign Key]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文