复制代码 代码如下:
SELECT * FROM (SELECT DISTINCT Name,Count(ID) as 人員個數,
sum(case when Sex='男' then 1 else 0 end) as 男人數,
sum(case when Sex='女' then 1 else 0 end) as 女人數
FROM Test group by Name) A
OUTER APPLY(
SELECT
[包含ID]= STUFF(REPLACE(REPLACE(
(
SELECT ID FROM Test N
WHERE Name = A.Name
FOR XML AUTO
), '<N/>', ''), 1, 1, '')
)N
新闻热点
疑难解答