SELECT t1.id, 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 MergedValues FROM formtable_main_43 t1 INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid GROUP BY t1.id需要展示更多T1中字段,该怎么该
时间: 2023-12-16 18:05:49 浏览: 84
如果您需要在结果中展示更多的 t1 中的字段,您可以在 SELECT 语句中添加这些字段,同时在 GROUP BY 语句中也需要包含这些字段。例如,如果您想要展示 t1 中的字段 t1.field1 和 t1.field2,您可以将 SELECT 语句修改为:
```
SELECT t1.id, t1.field1, t1.field2,
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 MergedValues
FROM formtable_main_43 t1
INNER JOIN formtable_main_43_dt1 t2 ON t1.id = t2.mainid
GROUP BY t1.id, t1.field1, t1.field2
```
请注意,根据您的需求,您可能还需要添加其他的 t1 字段。
阅读全文