我有一个非常简单的查询,但有些预订列重复,如果他们这样做我不想显示它们,但是整个行不一样我怎么能这样做如果行是重复显示一个最大总数。
SELECT PREMIUMYEAR,
LASTNAME,
FIRSTNAME,
BOOKING,
CLAIMTYPE,
DEPARTUREDATE,
[PLAN],
INCIDENT,
RESERVEAMOUNT,
FINALSTATUS,
AGE,
TOTAL
FROM dbo.[table]
答案 0 :(得分:4)
SELECT PREMIUMYEAR, LASTNAME, FIRSTNAME, BOOKING, CLAIMTYPE, DEPARTUREDATE, [PLAN], INCIDENT, RESERVEAMOUNT, FINALSTATUS, AGE, TOTAL
FROM (SELECT PREMIUMYEAR, LASTNAME, FIRSTNAME, BOOKING, CLAIMTYPE, DEPARTUREDATE, [PLAN], INCIDENT, RESERVEAMOUNT, FINALSTATUS, AGE, TOTAL,
ROW_NUMBER() OVER(PARTITION BY BOOKING ORDER BY TOTAL DESC) AS RowNum
FROM dbo.[table]) t
WHERE t.RowNum = 1