将列转换为SQL SERVER中的行 [英] Converting columns in to rows in SQL SERVER

查看:84
本文介绍了将列转换为SQL SERVER中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张如下表格。



Hi, I have a table like below.

nUserID	sDate	IN_FINGER	OUT_FINGER
4431	2018/10/03	08:33	16:17
4513	2018/10/03	05:11	16:03
4431	2018/10/04	08:30	16:20
4513	2018/10/04	04:27	15:45
4513	2018/10/06	05:41	14:03





我想将列转换为如下行





I want to convert columns into rows like below

nUserID	sDate	Stime	Ttype
4431	10/3/2018	8:33	IN
4431	10/3/2018	16:17	OUT
4513	10/3/2018	5:11	IN
4513	10/3/2018	16:03	OUT
4431	10/4/2018	8:30	IN
4431	10/4/2018	16:20	OUT
4513	10/4/2018	4:27	IN
4513	10/4/2018	15:45	OUT
4513	10/6/2018	5:41	IN
4513	10/6/2018	14:03	OUT





我怎样才能实现这一目标?



我尝试了什么:



我尝试过UNPIVOTING,但我不是查询专家所以我无法得到我想要的结果。



问候

Bibin



How can i achieve this?

What I have tried:

I have tried with UNPIVOTING, but I am not an expert in querying so I could not get the result I was looking for.

Regards
Bibin

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



从这里开始:使用PIVOT和UNPIVOT | Microsoft Docs [ ^ ]并学习如何操作!

亲自尝试,你可能会发现它并不像你想象的那么困难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

So start here: Using PIVOT and UNPIVOT | Microsoft Docs[^] and learn how to do it!
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于将列转换为SQL SERVER中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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