如何在sql server中使用sql包含相同的行? [英] how to incorporate the same line using sql in sql server?
问题描述
NIK IN / OUT DATE
10026 1 2015-07-07 14:15:09.000
10026 0 2015-07-06 14:16:28.000
10026 1 2015-07-06 14:16:37.000
10026 0 2015-07-08 05:26:17.000
i想得到如下结果:
NIK日期日期结束
10026 2015-07-07 14:15:09.000 null
10026 2015-07-06 14:16:28.000 2015-07-06 14:16:37.000
10026 null 2015-07-08 05:26:17.000
如何在sql server中使用sql基于字段(in-out)合并相同的行
< blockquote>如果我理解你的要求,我相信使用LAG和LEAD函数将是最简单的方法。
看看如何从结果集中的上一行或下一行获取数据 [ ^ ]
NIK IN/OUT DATE
10026 1 2015-07-07 14:15:09.000
10026 0 2015-07-06 14:16:28.000
10026 1 2015-07-06 14:16:37.000
10026 0 2015-07-08 05:26:17.000
i want the result like below:
NIK DATE IN DATE OUT
10026 2015-07-07 14:15:09.000 null
10026 2015-07-06 14:16:28.000 2015-07-06 14:16:37.000
10026 null 2015-07-08 05:26:17.000
how to incorporate the same line based on field (in-out) using sql in sql server
IF I understood correctly your requirement, I believe that using LAG and LEAD functions would be the easiest way.
Have a look at How to fetch data from the previous or next rows in the resultset[^]
这篇关于如何在sql server中使用sql包含相同的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!