当前位置:网站首页>sqlserver 多行合并成一行
sqlserver 多行合并成一行
2022-07-30 01:02:00 【Kimizhou_blog】
多行合并成一行笔记
with #twmpTable as(
select
a.F_ID id,
a.F_Code code,
b.F_Name name,
b.F_SQZSL num,
0 price,
F_SQBMCode department
from t_wms_out a
left join t_wms_out_detail b on a.F_ID = b.F_OutId
where a.F_SQLX = '100'--100 = 出库申请单
and a.F_ZZId = '3001'
)
select * from #twmpTable
-------------------------初级版本----------------
with #twmpTable as(
select
a.F_ID id,
a.F_Code code,
b.F_Name name,
b.F_SQZSL num,
0 price,
F_SQBMCode department
from t_wms_out a
left join t_wms_out_detail b on a.F_ID = b.F_OutId
where a.F_SQLX = '100'
and a.F_ZZId = '3001'
)
Select
id,
stuff((select ','+name from #twmpTable where id=t.id for xml path('')),1,1,'') name
From #twmpTable t
Group by id
-------------------------最终版本----------------
with #twmpTable as(
select
a.F_ID id,
a.F_Code code,
b.F_Name name,
b.F_SQZSL num,
0 price,
F_SQBMCode department
from t_wms_out a
left join t_wms_out_detail b on a.F_ID = b.F_OutId
where a.F_SQLX = '100'--100 = 出库申请单
and a.F_ZZId = '3001'
)
Select
id,
code,
stuff((select ','+name from #twmpTable where id=t.id for xml path('')),1,1,'') name,
sum(num) num,
sum(price) price,
department
From #twmpTable t
Group by
id,
code,
department
边栏推荐
- CMake Tutorial 巡礼(0)_总述
- 泰克Tektronix示波器软件TDS420|TDS430|TDS460上位机软件NS-Scope
- How many ways does Selenium upload files?I don't believe you have me
- npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
- Filebeat如何保证在日志文件被切割(或滚动rolling)时依然正确读取文件
- How do we-media people create explosive articles?These 3 types of articles are most likely to explode
- Minimum number to rotate array
- Finding a 2D Array
- 泰克Tektronix示波器软件TDS2012|TDS2014|TDS2022上位机软件NS-Scope
- 气路旋转连接器怎么用
猜你喜欢

验证框架-01

Interviews with big factories under the trend of layoffs: "ByteDance"

Superficial understanding of CNN

重建二叉树

Worthington Enzymatic Cell Harvest & Cell Adhesion and Harvest

Meetings OA To Be Meeting && All Meetings

CMake Tutorial 巡礼(1)_基础的起点

字符串替换空格

What majors become more popular the older they get?

Weekly recommended short video: What is R&D efficiency?It can achieve anti "involution"?
随机推荐
docker安装redis集群(含部署脚本)
Since the media increase play a short video?From the three aspects
软考 --- 数据库(5)数据库控制
Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles
Fabric Private Data Case
Fabric 私有数据案例
canvas 中如何实现物体的框选(六)
Print linked list from end to beginning
记笔记!电源自动测试系统测试电源纹波详细方法
裁员趋势下的大厂面试:“字节跳动”
【LeetCode每日一题】——404.左叶子之和
go语言解决自定义header的跨域问题
"The lighthouse factory" of China path: smart roll out from point to surface
测试员容易陷入的9大误区
[Training DAY16] ALFA [convex hull] [computational geometry]
Worthington Enzymatic Cell Harvest & Cell Adhesion and Harvest
这是一道非常有争议的题,我的分析如下: TCP/IP在多个层引入了安全机制,其中TLS协议位于______。 A.数据链路层 B.网络层 C.传输层 D.应用层
Detailed explanation of nacos cluster configuration
exness: U.S. GDP shrinks, yen bounces back
The solution to the bug, the test will no longer be blamed