
关于SQL语句:比如说一段SQL的查询结果为A,B,C,D也可能是A,C,D 怎么得到对应结果为A/B/C/D 也可能为A/C/D
也就是说我的那段SQL得到的查询结果只得到一个字段的信息,但是查询出的结果不一定是多少条,每条的中间要加上/请高手们不吝赐教在线等我的SQL为withSelectGrou...
也就是说我的那段SQL得到的查询结果只得到一个字段的信息,但是查询出的结果不一定是多少条,每条的中间要加上/ 请高手们不吝赐教 在线等
我的SQL为
with SelectGroup( GroupID,ParentID,Name )
as
(
select GroupID,ParentID,Name from [Group] where GroupID = 192 and IsDeleted = 'false' and GroupID >=2
union all
select g.GroupID,g.ParentID,g.Name from [Group] g
inner join SelectGroup sg on g.GroupID = sg.ParentID and g.IsDeleted = 'false' and g.GroupID >=2
)
select Name from SelectGroup order by GroupID 展开
我的SQL为
with SelectGroup( GroupID,ParentID,Name )
as
(
select GroupID,ParentID,Name from [Group] where GroupID = 192 and IsDeleted = 'false' and GroupID >=2
union all
select g.GroupID,g.ParentID,g.Name from [Group] g
inner join SelectGroup sg on g.GroupID = sg.ParentID and g.IsDeleted = 'false' and g.GroupID >=2
)
select Name from SelectGroup order by GroupID 展开
3个回答
展开全部
用function 处理吧
用cursor 查询出所有结果,每条结果 拼一个 / 在后面
将取得的结果拼成一个字符串
所有取完后,将最后一个 / 去除
返回该字符串
注意 如果结果太多字符串长度需要注意
用cursor 查询出所有结果,每条结果 拼一个 / 在后面
将取得的结果拼成一个字符串
所有取完后,将最后一个 / 去除
返回该字符串
注意 如果结果太多字符串长度需要注意
追问
能不能给个大概的SQL 不想再去查游标的使用方法了
追答
10g以上有一个 collect(column)函数,没用过,不知道是啥样,与你要的有点相似,但又不一样,其他没找到简便方法。
展开全部
declare @c varchar(1000)
set @c=''
select @c=@c+col_name+'/' from tab_name
where ..........
select @c
set @c=''
select @c=@c+col_name+'/' from tab_name
where ..........
select @c
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把你的sql语句写出来看看?
追问
sql贴在了问题补充上了 麻烦你看下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询