/****** YYYYMMDD(NUM), CHITEN(TXT)フィールドに付きNICHIJI(TXT)フィールドの最大値を取得 ******/ //共通 SELECT * FROM TABLE1 WHERE TABLE1.NICHIJI2 = (SELECT MAX(TMP.NICHIJI2) FROM TABLE1 TMP WHERE TMP.YYYYMMDD=TABLE1.YYYYMMDD AND TMP.CHITEN=TABLE1.CHITEN) //SQL Server SELECT * FROM GeoDatabase.dbo.TABLE1 WHERE STR(YYYYMMDD)+CHITEN+NICHIJI2 IN (SELECT STR(YYYYMMDD)+CHITEN+MAX(NICHIJI2) FROM GeoDatabase.dbo.TABLE1 GROUP BY YYYYMMDD,CHITEN) //Oracle SELECT * FROM TABLE1 WHERE TO_CHAR(YYYYMMDD)||CHITEN||NICHIJI IN (SELECT TO_CHAR(YYYYMMDD)||CHITEN||MAX(NICHIJI) FROM TABLE1 GROUP BY YYYYMMDD,CHITEN)
複数フィールドの組み合わせによるユニークな値ごとに最大値を取得する方法
2016/9/1 (木)