如何在 vb.net 中将行追加为列
我有两行,如下所示
regn_no date name Adress
5001 15 may 2010 A xyz
5001 13 jan 2011 B ABC
5001 14 july 2011 C PQR
,因为 regn_no 相等,我想将日期较大的行附加到日期较小的行。 我想要如下结果
regn_no date name Adress new_name new_Adress new_name2 add_2
5001 14 july 2011 A xyz B ABC C PQR
请帮忙 先感谢您
I have two rows as shown below
regn_no date name Adress
5001 15 may 2010 A xyz
5001 13 jan 2011 B ABC
5001 14 july 2011 C PQR
since regn_no is equal i want to append row with greater date to lower date.
i want result as below
regn_no date name Adress new_name new_Adress new_name2 add_2
5001 14 july 2011 A xyz B ABC C PQR
please help
thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Oracle(而不是 VB.net)中执行此操作更容易,因为 Oracle 为此提供了内置函数。但是,您还需要考虑更多场景。
如果您对给定 ID 进行了多次更改怎么办?您想将其显示在多列中,还是更像是一种“更改跟踪”显示,其中显示每次更改的旧值和新值?
对于最新行(第 15 行),不会有新地址,因此将为空。如果您不想选择该条件,则需要再添加一个条件(请参阅第二个查询..)
REGN_NO DATE1 N ADD N NEW
<预><代码> 5001 2010 年 5 月 13 日 B ABC A XYZ
5001 2010 年 5 月 15 日 A XYZ
其中 t1 为 (
选择 5001 regn_no, to_date('15-May-2010','DD-Mon-YYYY') date1,
'A' 名称,'XYZ' 来自双地址
联合所有
选择 5001 regn_no, to_date('13-May-2010','DD-Mon-YYYY') date1,
'B' 名称,'ABC' 地址来自双重)
从 ( 中选择 *
选择 t1.regn_no、t1.date1、t1.name、t1.address、
领先(t1.name)(按t1.regn_no分区
按 t1.date1 asc 排序) new_name,
引导(t1.Address)超过(按 t1.regn_no 分区
按 t1.date1 asc 排序)new_Address
从 t1
) 其中 not(new_name 为 null,new_address 为 null)
/
REGN_NO DATE1 N 添加 N 新内容
<小时>
<预><代码> 5001 2010 年 5 月 13 日 B ABC A XYZ
It is easier to do this in Oracle (instead of VB.net), since Oracle comes with built-in functions for this. However, there are some more scenarios you need to think about.
What if you had more than one change for a given ID? would you like to display it in multiple columns or it is more of a "change tracking" display where you show the old and new value for each change?
For the latest row (the one on 15th),there would be no new address, so it will be null. If you don't want to pick that up, you need to add one more condition (see second query..)
REGN_NO DATE1 N ADD N NEW
with t1 as (
select 5001 regn_no, to_date('15-May-2010','DD-Mon-YYYY') date1,
'A' name, 'XYZ' Address from dual
union all
select 5001 regn_no, to_date('13-May-2010','DD-Mon-YYYY') date1,
'B' name, 'ABC' address from dual)
select * from (
select t1.regn_no, t1.date1, t1.name, t1.address,
lead(t1.name) over (partition by t1.regn_no
order by t1.date1 asc) new_name,
lead(t1.Address) over (partition by t1.regn_no
order by t1.date1 asc) new_Address
from t1
) where not (new_name is null and new_address is null)
/
REGN_NO DATE1 N ADD N NEW