简体   繁体   中英

merge two rows into one row in sql?

I have a table as:

Serveur Total Date
#01 200 2022-01-01 14:11:50.000
#01 100 2022-01-01 22:19:33.000
#02 150 2022-01-01 14:55:35.000
#02 300 2022-01-01 21:45:28.000
#03 500 2022-01-01 21:43:21.000

But I want the output as follows(I want to use this output to inner join with some other table):

Serveur Total_1 Total_2
#01 200 100
#02 150 300
#03 500 0

I guess you are using Microsoft SQL Please follow the link below for syntax and examples on how to pivot the data within tables https://docs.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver16

Or you can use sun queries to pivot which is time consuming and dirty way of doing it.

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