Athena Min()功能使无效

发布于 2025-02-02 10:57:41 字数 357 浏览 3 评论 0原文

我试图带回三个不是无效的属性的最小日期。可能会有多行,所以我需要分组以找到键的属性的最低日期,而三个最低数字中的最低数字

“在此处输入图像描述”

因此,对于下面的图像,我想返回09/09/00,问题是min(),因为最低的值和操作员也这样做。有很好的解决方案吗?

我们想要第一个和第二个日期的最小

key date_1 date_2 Date_3
1 12/31/12 1/2/18 NULL
1 5/3/15 5/17/08 3/17/19
1 NULL 9/9/00 9/28/07

I am attempting to bring back the smallest date of three attributes that is not null. There could be multiple rows so I need to group to find the lowest of date of the attribute for the key and the lowest of the three lowest numbers

enter image description here

So with the image below I would want to return 09/09/00 the problem is MIN() keeps bringing back null as the lowest value and operators do the same. Is there a good solution for this?

We want the min of the first and second date and if both of all of those dates are null return the min third_date

key date_1 date_2 Date_3
1 12/31/12 1/2/18 NULL
1 5/3/15 5/17/08 3/17/19
1 NULL 9/9/00 9/28/07

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

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

发布评论

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

评论(1

风柔一江水 2025-02-09 10:57:41

您可以在此处使用Union方法:

SELECT "key", MIN(date) AS min_date
FROM
(
    SELECT "key", date_1 AS date FROM yourTable
    UNION ALL
    SELECT "key", date_2 FROM yourTable
    UNION ALL
    SELECT "key", date_3 FROM yourTable
) t
GROUP BY "key";

请注意,您应该避免命名,这通常是保留的SQL关键字。

You could use a UNION approach here:

SELECT "key", MIN(date) AS min_date
FROM
(
    SELECT "key", date_1 AS date FROM yourTable
    UNION ALL
    SELECT "key", date_2 FROM yourTable
    UNION ALL
    SELECT "key", date_3 FROM yourTable
) t
GROUP BY "key";

Note that you should avoid naming your columns key, which is usually a reserved SQL keyword.

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