小编Roh*_*han的帖子

如何在sql server中使用pivot(没有聚合)?

请帮我解决这个问题:给你一个表,包含两列:列是以下之一:

Doctor
Professor
Singer
Actor
Run Code Online (Sandbox Code Playgroud)

编写查询以输出相应occ下面的名称.采用以下格式:

+--------+-----------+--------+------+

| Doctor | Professor | Singer | Actor|

+--------+-----------+--------+------+
Run Code Online (Sandbox Code Playgroud)

名称必须按字母顺序排列.

样本输入

Name        Occupation
Meera       Singer
Ashely      Professor
Ketty       Professor
Christeen   Professor
Jane        Actor
Jenny       Doctor
Priya       Singer    
Run Code Online (Sandbox Code Playgroud)

样本输出

Jenny    Ashley     Meera  Jane

Samantha Christeen  Priya  Julia

NULL     Ketty      NULL   Maria
Run Code Online (Sandbox Code Playgroud)

注意

当没有更多名称对应于职业时,打印"NULL".

我试过用:

SELECT *
FROM
(
SELECT [Name], [Occupation] 
FROM occupations 
) AS source
PIVOT
(
    max([Name])
    FOR [occupation] IN ([Doctor], [Professor], [Singer], [Actor]) 
) as pvt;
Run Code Online (Sandbox Code Playgroud)

它给出了以下输出:

Priya Priyanka Kristeen Samantha …
Run Code Online (Sandbox Code Playgroud)

sql database sql-server

5
推荐指数
2
解决办法
8659
查看次数

流类型中的(a:?string)和(a ?: string)之间有什么区别?

a?: stringa: ?stringFlow 之间有什么区别?

function concat(a: ?string, b: ?string): string {
}
Run Code Online (Sandbox Code Playgroud)

function concat(a?: string, b?: string): string {
}
Run Code Online (Sandbox Code Playgroud)

javascript reactjs flowtype

4
推荐指数
1
解决办法
648
查看次数

标签 统计

database ×1

flowtype ×1

javascript ×1

reactjs ×1

sql ×1

sql-server ×1