如何在sql server中使用sql包含相同的行? [英] how to incorporate the same line using sql in sql server?

查看:116
本文介绍了如何在sql server中使用sql包含相同的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆