[英]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):但我想要 output 如下(我想用这个 output 与其他表进行内连接):
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我猜您正在使用 Microsoft SQL 请按照以下链接获取有关如何 pivot 表https: //docs.microsoft.com/en-us-sql/sql 中的数据的语法和示例透视和取消透视?视图=sql-server-ver16
Or you can use sun queries to pivot which is time consuming and dirty way of doing it.或者您可以对 pivot 使用 sun 查询,这是一种耗时且肮脏的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.