这是我的表值:
我想用这张表做透视。结果应采用格式
示例输出:
print
我尝试了以下内容,
print("Copying... ", end="", flush=True)
shutil.copytree(src, dest)
print("DONE")
但是,它只返回一行。因为 MAX
我怎样才能做到这一点,
答案 0 :(得分:1)
您可以添加ROW_NUMBER
列:
WITH cte AS
(
SELECT *
FROM (SELECT *, r = ROW_NUMBER() OVER(PARTITION BY occupation ORDER BY name)
FROM #Occupations) AS s
PIVOT
(
MAX(name)
FOR occupation IN (Doctor, Professor, Singer, Actor)
)pvt
)
SELECT Doctor, Professor, Singer, Actor
FROM cte;
的 LiveDemo
强>
输出:
╔══════════╦═══════════╦════════╦═══════╗
║ Doctor ║ Professor ║ Singer ║ Actor ║
╠══════════╬═══════════╬════════╬═══════╣
║ Jenny ║ Ashley ║ Meera ║ Jane ║
║ Samantha ║ Christeen ║ Priya ║ Julia ║
║ ║ Ketty ║ ║ Maria ║
╚══════════╩═══════════╩════════╩═══════╝