如何在SQL Server中将多行合并为单行 [英] how to get multiple rows into single row in sql server

查看:88
本文介绍了如何在SQL Server中将多行合并为单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个delima,我不确定这是否可行.但我有一张桌子,可以说

年龄|类型名称|剂量
1药x 1毫升
2疫苗y 2毫升
3水z 3ml
1支疫苗4毫升
2药e 5毫升

我希望能够将此数据作为一行与data1中的数据返回一列,并以逗号分隔.

因此结果将是

1列
年龄类型名称剂量
1个Medix,疫苗x,1ml,4ml

如何用于xmlpath()
谁能帮我这个忙.

谢谢您,

Hello,

I have a delima, and i am not really sure if this possible. But i have a table like lets say

age | type | name | dose
1 medicine x 1ml
2 vaccine y 2ml
3 water z 3ml
1 vaccine a 4ml
2 medicine e 5ml

i want to be able to return this as one row with the data from data1 in one column separated by commas.

so the result would be

1 Column
age type name dose
1 medi,vaccine x,a 1ml,4ml

how to use for xmlpath()
can anyone help me with this.

Thank you,

推荐答案

阅读

使用Stuff函数获取列值.

问候
use Stuff function for column values.

Regards


这篇关于如何在SQL Server中将多行合并为单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆