1

我可以使用一些 SQL 帮助来解决以下问题。

我有一个包含以下列和数据的表。

CUSTOMER PAYMENT_YEAR BILLS_PER_YEAR BILL_NUMBER
Chris    2010         1              1
Chris    2010         2              2
Chris    2010         3              3

我想返回所有三行,但所有 3 行中的最大 bills_per_year 值。它会像这样。

CUSTOMER  PAYMENT_YEAR  BILLS_PER_YEAR  BILL_NUMBER
Chris     2010          3               1
Chris     2010          3               2
Chris     2010          3               3
4

2 回答 2

2

它对你有用吗?

SELECT CUSTOMER, PAYMENT_YEAR, BILLS_PER_YEAR, BILL_NUMBER,
MAX(BILLS_PER_YEAR) OVER (PARTITION BY CUSTOMER,PAYMENT_YEAR) as max_per_year
FROM table1
于 2013-01-09T04:21:58.783 回答
1

这是你的意思吗?

SELECT 
    CUSTOMER, 
    PAYMENT_YEAR, 
    MAX(BILLS_PER_YEAR) OVER(PARTITION BY CUSTOMER, PAYMENT_YEAR) BILLS_PER_YEAR,
    BILL_NUMBER
FROM TableName
于 2013-01-09T04:22:00.720 回答