SELECT t1.id, t1.[requestId] AS t1_requestId, t1.[gf] AS '供方', t1.[htmc] AS '合同名称', t1.[htbh] AS '合同编号', t1.[sjbh] AS '编号', t1.[qdrq] AS '签订日期', t1.[qsrq] AS '起始日期', t1.[jzrq] AS '截止日期', t1.[zje] AS '总金额', t1.[zds] AS '总吨数', t1.[rksj] AS '入库时间', t1.[chpt] AS '撮合平台', t1.[qsfs] AS '签署方式', t1.[gfjc] AS '供方简称', t1.[cclx] AS '持仓类型', CAST(t1.[htwj] AS VARCHAR(MAX)) AS '合同文件', STUFF( (SELECT ',' + CONVERT(VARCHAR, CASE WHEN ISNUMERIC(REPLACE(t2.hsdj, ',', '')) = 1 THEN CAST(REPLACE(t2.hsdj, ',', '') AS FLOAT) END) FROM formtable_main_43_dt1 t2 WHERE t1.id = t2.mainid FOR XML PATH ('') ), 1, 1, '' ) AS '采购单价' FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id, t1.[requestId], t1.[gf], t1.[htmc], t1.[htbh], t1.[sjbh], t1.[qdrq], t1.[qsrq], t1.[jzrq], t1.[zje], t1.[zds], t1.[rksj], t1.[chpt], t1.[qsfs], t1.[gfjc], t1.[cclx], CAST(t1.[htwj] AS VARCHAR(MAX))中t2表再多一个pp字段,并显示为“品牌”
时间: 2024-01-23 20:04:26 浏览: 68
你的问题是关于SQL语句的,你想让t2表再多一个pp字段,并显示为“品牌”。那么你可以按照以下的SQL语句进行修改:
```
SELECT t1.id,
t1.[requestId] AS t1_requestId,
t1.[gf] AS '供方',
t1.[htmc] AS '合同名称',
t1.[htbh] AS '合同编号',
t1.[sjbh] AS '编号',
t1.[qdrq] AS '签订日期',
t1.[qsrq] AS '起始日期',
t1.[jzrq] AS '截止日期',
t1.[zje] AS '总金额',
t1.[zds] AS '总吨数',
t1.[rksj] AS '入库时间',
t1.[chpt] AS '撮合平台',
t1.[qsfs] AS '签署方式',
t1.[gfjc] AS '供方简称',
t1.[cclx] AS '持仓类型',
CAST(t1.[htwj] AS VARCHAR(MAX)) AS '合同文件',
STUFF((SELECT ',' + CONVERT(VARCHAR, CASE WHEN ISNUMERIC(REPLACE(t2.hsdj, ',', '')) = 1 THEN CAST(REPLACE(t2.hsdj, ',', '') AS FLOAT) END)
FROM formtable_main_43_dt1 t2
WHERE t1.id = t2.mainid
FOR XML PATH ('')), 1, 1, '') AS '采购单价',
t2.[pp] AS '品牌'
FROM formtable_main_43 t1
INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid
GROUP BY t1.id,
t1.[requestId],
t1.[gf],
t1.[htmc],
t1.[htbh],
t1.[sjbh],
t1.[qdrq],
t1.[qsrq],
t1.[jzrq],
t1.[zje],
t1.[zds],
t1.[rksj],
t1.[chpt],
t1.[qsfs],
t1.[gfjc],
t1.[cclx],
CAST(t1.[htwj] AS VARCHAR(MAX)),
t2.[pp];
```
以上是修改后的SQL语句,其中加入了一个名为pp的字段,这个字段来自于t2表,并且显示为“品牌”。希望这个回答能够帮助到你。
阅读全文