簡體   English   中英

SQL Server:按用戶 ID 分組 - 將 2 行合並為 1 行

[英]SQL Server : group by userId - merge 2 rows into 1 row

當我通過UserName查詢用戶時,我得到兩行,但我想將它們合並為一行。 例如,

當前結果:

在此處輸入圖片說明

想要的結果:

進入

您可以進行聚合:

select userid, username, 
       max(case when phonetype = 'primary' then phonenumber end) as primary_no,
       max(case when phonetype = 'secondary' then phonenumber end) as secondary_no
from t
group by userid, username;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM