表A字段与内容如下:都是varchar类型sName sValue
001 a
001 b
002 a
002 a
002 b============================
要得到如下结果,按sName分组:001 ab
002 aab请问SQL语句怎么写?谢谢.
001 a
001 b
002 a
002 a
002 b============================
要得到如下结果,按sName分组:001 ab
002 aab请问SQL语句怎么写?谢谢.
解决方案 »
- TStaticText的字体颜色问题!
- 模态窗口的销毁与重显示问题
- Delphi Q群:19072429 欢迎大家加入~!
- 如何获取另一个exe程序的窗口上的label的caption值
- 请问做报表用什么(第三方)控件好?
- 各位专家,他们现在给我的例子不全面,要么没有判断EDIT.TXT<>'',要么没有判断是否敲的回车键,请给我全面的例子 !!!!if edit1.txt<
- 数据拷贝
- pchar 与string,char有什么区别?
- 软件报价
- 教我如何在delphi4中索引
- 有一个strpcopy问题,向大家请教
- 为什么会出现错误 canvert not convet variant of type (null) into type (String)
insert into @t values('001','b')
insert into @t values('002','a')
insert into @t values('002','a')
insert into @t values('002','b')select * from @t-- select sname, sum(svalue)
-- from @t
-- group by sname可惜不支持,自己动手吧
returns varchar(128)
as
begin
declare @Fee varchar(128)
set @Fee=''
select @Fee=@Fee+svalue+cast(Fee as varchar) from a where IDA=@IDA
set @Fee=rtrim(@Fee)
return @Fee
endselect *, Fee=dbo.fn(sname) from a A
只用一条SQL语句不太好弄,后来用游标
drop table tb
go
create table tb(sName varchar(10),sValue varchar(10))
go
insert into tb
select '001','a' union all
select '001','b' union all
select '002','a' union all
select '002','a' union all
select '002','b'
go
if object_id('uf_sumvalue') is not null
drop function uf_sumvalue
go
create function uf_sumvalue(@sName varchar(10))
returns varchar(100)
as
begin
declare @str varchar(100)
select @str=isnull(@str,'')+sValue from tb where sName=@sName
return @str
end
go
select sName,sValue=dbo.uf_sumvalue(sName) from tb group by sName