create table t
(id1 int ,id2 int ,id3 char(10))insert into t
select 1,2,1
union
select 1,2,2
union
select 1,3,1
union
select 1,3,2
union
select 1,4,2
create function f_str1(@id1 int,@id2 int)
returns varchar(1000)
as
begin
declare @r varchar(1000)
set @r = ''
select @r = @r+','+rtrim(id3) from t where id1=@id1 and id2=@id2
return(stuff(@r,1,1,''))
endselect id1,id2,dbo.f_str1(id1,id2) from t group by id1,id2
(id1 int ,id2 int ,id3 char(10))insert into t
select 1,2,1
union
select 1,2,2
union
select 1,3,1
union
select 1,3,2
union
select 1,4,2
create function f_str1(@id1 int,@id2 int)
returns varchar(1000)
as
begin
declare @r varchar(1000)
set @r = ''
select @r = @r+','+rtrim(id3) from t where id1=@id1 and id2=@id2
return(stuff(@r,1,1,''))
endselect id1,id2,dbo.f_str1(id1,id2) from t group by id1,id2
解决方案 »
- 如何判断动态表达式是否成立
- SQL统计问题
- 请教sql高手:通过一条sql语句,可以使查询结果按指定格式显示的问题
- 为什么这个游标只能执行一次呢。。。。。
- 求介绍存储过程的书籍!!
- 怎样在SQL Server7.0中写个存储过程,读取Sybase的表内容?我不熟悉Sybase,没分了
- 求SQL Server 不允许进行远程连接,error: 26 的解决办法
- 请问在一个表里 有两个字段都是需要唯一的,是不是一个设置为主键,另一个建一个unique索引。
- 请问 一个用户用一次登录(当然不是sa了)可以同时操作sql server 上的两个库吗
- 怎么将MySQL里的表数据导入到SqlServer里面
- 事务回滚rollback会关闭游标问题?(难度:100)
- 请教一SQL语句
select * from #t a where not exists
(select * from #t b where a.id1=b.id1
and a.id2=b.id2 and b.id3<a.id3))
c inner join (
select (cast(id1 as varchar(10))+' '+cast(id2 as varchar(10))) as mm
,count(*) as counts from #t group by (cast(id1 as varchar(10))+' '+cast(id2 as varchar(10)))) d
on (cast(c.id1 as varchar(10))+' '+cast(c.id2 as varchar(10)))=d.mm