表中的重新调整值 [英] rearaneg values in table

查看:73
本文介绍了表中的重新调整值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在表中有这样的记录:



i have records in table like this:

id   v1    v2   v3
1  587     21   759   
2  230     4    495


现在我要像下面这样输出:


now i want ouput like below:

id  v1       v2
1  587     21   
2  587     759
3  230     4
4  230     495




我被困在这里,不知道该查询什么.

p帮帮我

感谢




i am stuck here don''t know what will be query for this.

p help me

thanks

推荐答案

尝试:
select id,v1,v2 from [table] order by id


正如您所描述的输入和输出值

很明显,您希望将v2和v3列作为结果表中的行

要获得您的问题中所述的相同输出,
使用下面给出的查询

As you have described Input and output values

it is clear that you want v2 and v3 columns as row in resultant table

to get same output described in your question,
use query given below

select row_number() over(partition by id,v1 order by id,v1) as id,v1,v2 from
(
select id,v1,v2 from table
union all
select id,v1,v3 as v2 from table
) as a
order by id,v1



祝您编码愉快!
:)



Happy Coding!
:)


这篇关于表中的重新调整值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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