新人求问,没有多少分,刚来,多谢大家了
新人求问,没有多少分,刚来,谢谢大家了
TABLE1 TABLE2
ID Hao NF ID Hao NF
1 3 2006 3 3 2007
2 3 2006 4 9 2006
3 3 2007
4 9 2006
5 9 2005
大家看懂了吧?我想从table1得到table2,以Hao为分类,每一类都把最大年份NF的选出来.这个怎么实现?谢谢大家!
------解决方案--------------------
select a.* from table1 a,(select hao,max(nf) as nf from table1 group by hao) b where a.hao=b.hao and a.nf=b.nf
------解决方案--------------------
可以用rownumber()函数
select * from
(select a.*,rownumber() over(partition by Hao order by NF DESC) as order_id
from TABLE1 a
) b
where order_id = 1
TABLE1 TABLE2
ID Hao NF ID Hao NF
1 3 2006 3 3 2007
2 3 2006 4 9 2006
3 3 2007
4 9 2006
5 9 2005
大家看懂了吧?我想从table1得到table2,以Hao为分类,每一类都把最大年份NF的选出来.这个怎么实现?谢谢大家!
------解决方案--------------------
select a.* from table1 a,(select hao,max(nf) as nf from table1 group by hao) b where a.hao=b.hao and a.nf=b.nf
------解决方案--------------------
可以用rownumber()函数
select * from
(select a.*,rownumber() over(partition by Hao order by NF DESC) as order_id
from TABLE1 a
) b
where order_id = 1