简单问题:

bh586 2006-10-21 09:12:12
表格如下:
id num
01 4.5
04 4.5
04 20
06 11
07 0.99
10 201
10 11
12 201
14 11
15 201
15 0.99
.. ...

num是decimal,无规则变化。想把相同num 的id 找出来。
比如
01 04
06 10 14
07 15
10 12 15等等。
...全文
127 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyxfly 2006-10-22
  • 打赏
  • 举报
回复
07 (x) 15 (y)
06 (x) 10 (z) 14 (x)
10 (y) 12 (y) 15 x)
???
bh586 2006-10-22
  • 打赏
  • 举报
回复
好的。
如果再想对相同num的id分别做出不同的处理:
比如
07 (x) 15 (y)
06 (x) 10 (z) 14 (x)
10 (y) 12 (y) 15 x)
又应该如何
xyxfly 2006-10-22
  • 打赏
  • 举报
回复
07 x 15 y .99
06 x 10 z 14 x 11


这个结果是怎么来的,总有一定规则吧,把你的规则说说看

看样子不太好实现
bh586 2006-10-22
  • 打赏
  • 举报
回复
就是对相同num的id如07 和15 分别处理(比如另外的查询)

形成这样的结果:
07 x 15 y .99
06 x 10 z 14 x 11
xyxfly 2006-10-21
  • 打赏
  • 举报
回复

id num
-------------------------------------------------- ------------
07 15 .99
01 04 4.50
06 10 14 11.00
04 20.00
10 12 15 201.00


这样?
xyxfly 2006-10-21
  • 打赏
  • 举报
回复
create table test
(id varchar(10), num decimal(10,2))
insert test
select '01', 4.5 union
select '04', 4.5 union
select '04', 20 union
select '06', 11 union
select '07', 0.99 union
select '10', 201 union
select '10', 11 union
select '12', 201 union
select '14', 11 union
select '15', 201 union
select '15', 0.99

go
create function f_merge(@col decimal(10,2))
returns varchar(50)
as
begin
declare @sql varchar(50)
set @sql=''
select @sql=@sql+' '+id from test where num=@col
return stuff(@sql,1,1,'')
end
go

select dbo.f_merge(num) id,num from test group by num


drop table test
drop function f_merge

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧