获取第一条记录 [英] to fetch first record
本文介绍了获取第一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我这个吗
i需要从每组记录中获取第一条记录
相同的emp id。
i不能使用group by因为我想获取对应于特定empid的所有字段
。
plz建议解决方案这一个
问候,
Sangram
解决方案
你能发布一些定义和数据吗?
尝试db2 olap函数rank / row_number over(partition by ...)
作为一个例子,你的员工表中的第一个双倍或三倍的样本
数据库。
然后运行:
,数据为
(
选择row_number()over(partition by id)为num,id,name from工作人员
)
选择id,来自数据的名称,其中num = 1
;
是这样你想要的吗?
hi,
can someone plz help me on this one
i need to fetch the first record from every group of records with the
same emp id.
i cannot use group by because i want to fetch all the fields
corresponding to a particular empid.
plz suggest a solution for this one
regards,
Sangram
解决方案can you post some talbe definition and data?
try db2 olap function rank/row_number over(partition by ...)
as a example, first double or triple your staff table in sample
database.
then run:
with data as
(
select row_number() over (partition by id) as num, id, name from staff
)
select id, name from data where num = 1
;
is this way your want?
这篇关于获取第一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文