[英]To move column value to next row using sql stored procedure
在下面的查詢中,我從表中選擇值,它具有4列名稱,年齡,類別,rollno。並且我想在2列中顯示它(例如)以使2列值移動到下一行和4列值到下一行。請幫助我做到這一點。
StudentID|name/age|class/Roll no|
1 xxx 2
1 5 123556
2 yyy 2
2 5 123557
Select studentid,name.age,class,roll no from student
您可以UNION ALL
並使用2個查詢。 我必須將年齡轉換為varchar,以便可以在name.age列中輸入
select id, name as 'name.age', class as 'class.rollno'
from student
union all
select id, cast(age as varchar), rollno
from student
order by id, name desc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.