将3列分组为1列

时间:2018-08-05 10:08:48

标签: sql

我是SQL的新手,所以也许这个问题太基本了,或者也许无法解决。我可以在SQL Server中将3列分组为1列吗?

它是这样的

 WorkLoc    Status           Total_Employee
                       Total      Man    Woman
Malaysia | FullTime | 3       | 2        | 1 | 
Malaysia | Contract | 2       | 2        |   |

所有3列(WorkLoc,Status和Total_Employee)都位于3个不同的表中

3 个答案:

答案 0 :(得分:2)

SELECT Column 1 As Title 1, Column 2 As Title 2, CONCAT( Column A , Column B,  Column C) AS title
FROM Table

https://docs.microsoft.com/en-us/sql/t-sql/functions/concat-transact-sql?view=sql-server-2017

答案 1 :(得分:0)

我认为您想通过使用CONCAT添加3列

select WorkLoc,status,Total, concat(totalman,totalwomen) as totalemployee from yourtable

答案 2 :(得分:0)

About CONCAT Function

SELECT CONCAT( name, middlename, lastname ) AS Result  
FROM Table

如果有Null值,您可以这样做。

SET CONCAT_NULL_YIELDS_NULL {ON|OFF}

带有分隔符;

 SELECT CONCAT( '-', name, middlename, lastname) AS Result  
    FROM Table