简体   繁体   中英

How to merge rows in one using SQL Server 2008

I have a SQL query like this

在此处输入图片说明

What I want is showing one row and adding columns dynamically

Like this:

在此处输入图片说明

How can I do that?

you must using pivot query.

SELECT cotation_study_uid, contation_label,[OMNIPAQUE 350*50ML] AS col1, [Crane TDM] AS col2, [Annulation produit] AS col3
(SELECT *
FROM yourtable)p
PIVOT (SUM(contation_prix) FOR cotation_label IN ('OMNIPAQUE 350*50ML', 'Crane TDM', 'Annulation produit'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM