选择属性b,其中属性a在sql中的groupby之后是最大

发布于 2025-02-09 17:50:49 字数 608 浏览 2 评论 0原文

给定下表:

ID价格日期
134A
142B
234A

我想在ID中有一排,而价格为

ID价格日期
142B
234A

最大 ID和选择ID,日期,最大(价格)导致错误组成的子句,带有非汇总功能

Given the following table:

IDPriceDate
134a
142b
234a

I would like to have one row per ID where the price was maximal

IDPriceDate
142b
234a

Trying to groupby ID and selecting ID, Date, MAX(Price) results in the error GROUP BY clause with non aggregate functions

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

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

发布评论

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

评论(1

宁愿没拥抱 2025-02-16 17:50:49

您可以使用row_number。

SELECT *
FROM 
your_table_name
QUALIFY ROW_NUMBER() OVER (partition by id order by price desc) = 1;

资格条款用于过滤有序分析的结果
根据用户指定的搜索条件功能。我们可以使用
选择语句中的此条件条款以获取特定
订单值。

You can use row_number.

SELECT *
FROM 
your_table_name
QUALIFY ROW_NUMBER() OVER (partition by id order by price desc) = 1;

The Qualify clause is used to filter the results of ordered analytical
function according to user‑specified search conditions. We can use
this conditional clause in the SELECT statement to get the particular
order values.

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