将列分组为一列

时间:2013-09-20 13:54:58

标签: sql

我有一个选择

Select b.BookingID, c.CustName, c.CustEmail, c.CustAdd
from  Booking b
INNER JOIN Customer c ON b.CustID = c.CustID

Booking Id | CustName | CustEmail | CustAdd
1          | Wes Sk   | Wes@Gmail | 18 Blah 

如何合并列以生成

Booking Id | Cust
1          | Wes Sk Wes@Gmail 18 Blah 

2 个答案:

答案 0 :(得分:3)

这应该适用于oracle和postgresql。对于MSSQL,您可以使用“+”符号代替“||”。

SELECT b.BookingID, c.CustName || ' ' || c.CustEmail || ' ' || c.CustAdd AS Cust
FROM Booking b
INNER JOIN Customer c ON b.CustID = c.CustID

答案 1 :(得分:1)

您可以连接查询中的字段。

Select b.BookingID, c.CustName + ' ' + c.CustEmail + ' ' + c.CustAdd As Cust
from  Booking b
INNER JOIN Customer c ON b.CustID = c.CustID