table A:
A B C D E F
a b c d 3 f
a b c d 4 g
e w w w 3 f
e w w 4 t
....
要選出相同記錄的E最大值的那條 F值會不一樣
》》》》結果
a b c d 4 g
e w w w 4 t
想不出來啊....
------解决思路----------------------
SELECT A,B,C,D,E,F FROM(sql2005+
SELECT *,ROW_NUMBER()OVER(PARTITION BY A,B,C,D ORDER BY E DESC)RN
FROM tableA
)T WHERE RN=1
------解决思路----------------------
SELECT *
FROM A T1
WHERE NOT EXISTS(
SELECT 1
FROM A T2
WHERE T2.E>T1.E
)
------解决思路----------------------
開始想到row_number()函數,但是結果有兩條數據。
可以這樣寫
select * from tableA where E=(select max(E) from tableA)
------解决思路----------------------
select * from tablea as a where not exists(select 1 from tablea where a=a.a and b.=a.b and c=a.c and d=a.d and e>a.e)