我可以使用SQL的一些帮助来解决以下问题。
我有一个包含以下列和数据的表。
CUSTOMER PAYMENT_YEAR BILLS_PER_YEAR BILL_NUMBER
Chris 2010 1 1
Chris 2010 2 2
Chris 2010 3 3
我想返回所有三行,但在所有3行中都包含max bills_per_year值。 它会是这样的。
CUSTOMER PAYMENT_YEAR BILLS_PER_YEAR BILL_NUMBER
Chris 2010 3 1
Chris 2010 3 2
Chris 2010 3 3
答案 0 :(得分: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
答案 1 :(得分:1)
这是你的意思吗?
SELECT
CUSTOMER,
PAYMENT_YEAR,
MAX(BILLS_PER_YEAR) OVER(PARTITION BY CUSTOMER, PAYMENT_YEAR) BILLS_PER_YEAR,
BILL_NUMBER
FROM TableName