记录最大日期

扫码查看
Let's assume I extract some set of data.i.e.SELECT A, dateFROM tableI want just the record with the max date (for each value of A). I could write SELECT A, col_date FROM TABLENAME t_ext WHERE col_date = (SELECT MAX (col_date) FROM TABLENAME t_in WHERE t_in.A = t_ext.A)But my query is really long... is there a more compact way using ANALYTIC FUNCTION to do the same? 解决方案 The analytic function approach would look something likeSELECT a, some_date_column FROM (SELECT a, some_date_column, rank() over (partition by a order by some_date_column desc) rnk FROM tablename) WHERE rnk = 1Note that depending on how you want to handle ties (or whether ties are possible in your data model), you may want to use either the ROW_NUMBER or the DENSE_RANK analytic function rather than RANK. 这篇关于记录最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 08:09
查看更多