读书人

oracle 输出每个分组的第一行,该怎么

发布时间: 2012-03-16 16:34:56 作者: rapoo

oracle 输出每个分组的第一行
ID Value
1 89
1 92
1 78
2 96
2 99
3 72
3 94
4 88
==========
输出结果
ID Value
1 89
2 96
3 72
4 88
输出结果是每一个分组的第一行,该如何写?

select ID,Value from tab_1

[解决办法]
select ID,Value from tab_1 group by id,Value;
[解决办法]

SQL code
select sub.id, sub.value from(with a as (select '1' as ID, '89' as value from dualunion allselect '1','92' from dualunion allselect '1','78' from dualunion allselect '2','96' from dualunion allselect '2','99' from dualunion allselect '3','72' from dualunion allselect '3','94' from dualunion allselect '4','88' from dual)select id,value,row_number() over (partition by id order by id) cnt from a) subwhere sub.cnt = 1; 

读书人网 >oracle

热点推荐