我想使用SQL查询在单个列中打印2列值。 [英] i want to print 2 column value in a single column using sql query.
本文介绍了我想使用SQL查询在单个列中打印2列值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个学生表和矩阵
学生表中的
列是 -
studentid studentname
1001 ashish
1002 shiva
1003 hasan
1004 hina
和矩阵表列是 -
seatno studentid
1 1001
2 1002
3 1003
4 1004
i希望使用sql查询在单个列中打印2列值,例如
学生
1,ashish
2,shiva
3,hasan
4,hina
i have 2 table student and matrix
in student table columns are-
studentid studentname
1001 ashish
1002 shiva
1003 hasan
1004 hina
and in matrix table columns are-
seatno studentid
1 1001
2 1002
3 1003
4 1004
i want to print 2 column value in a single column using sql query like
student
1,ashish
2,shiva
3,hasan
4,hina
推荐答案
尝试这个...
try this one...
Select
cast(seatno as varchar) + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
castSeatnno to varchar
That should work
Select
cast(seatno as varchar(10)) + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
嘿,你可以使用这个查询
选择
seatno +','+学生名
来自StudentTable s
内联系MatrixTable m on m.Studentid = s.studentID
hey you could use this query
Select
seatno + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
这篇关于我想使用SQL查询在单个列中打印2列值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文