count. avg. min. str哪个不是聚合函数
答案:2 悬赏:30 手机版
解决时间 2021-03-03 05:57
- 提问者网友:書生途
- 2021-03-02 14:00
count. avg. min. str哪个不是聚合函数
最佳答案
- 五星知识达人网友:深街酒徒
- 2021-03-02 14:12
利用SUM、AVG、COUNT、COUNT(*)、MAX 和 MIN是无法做到的。因为这些都是对数值的聚合。不过我们可以通过自定义函数的方式来解决这个问题。
1.首先建立测试表,并插入测试数据:
复制代码 代码如下:
create table AggregationTable(Id int, [Name] varchar(10))
go
insert into Aggre www.hbbz08.com gationTable
select 1,'赵' union all
select 2,'钱' union all
select 1,'孙' union all
select 1,'李' union all
select 2,'周'
go
2.创建自定义字符串聚合函数
复制代码 代码如下:
Create FUNCTION AggregateString
(
@Id int
)
RETURNS varchar(1024)
AS
BEGIN
declare @Str varchar(1024)
set @Str = ''
select @Str = @Str + [Name] from AggregationTable
where [Id] = @Id
return @Str
END
GO
3.执行下面的语句,并查看结果
复制代码 代码如下:
select dbo.AggregateString(Id),Id from AggregationTable
group by Id
1.首先建立测试表,并插入测试数据:
复制代码 代码如下:
create table AggregationTable(Id int, [Name] varchar(10))
go
insert into Aggre www.hbbz08.com gationTable
select 1,'赵' union all
select 2,'钱' union all
select 1,'孙' union all
select 1,'李' union all
select 2,'周'
go
2.创建自定义字符串聚合函数
复制代码 代码如下:
Create FUNCTION AggregateString
(
@Id int
)
RETURNS varchar(1024)
AS
BEGIN
declare @Str varchar(1024)
set @Str = ''
select @Str = @Str + [Name] from AggregationTable
where [Id] = @Id
return @Str
END
GO
3.执行下面的语句,并查看结果
复制代码 代码如下:
select dbo.AggregateString(Id),Id from AggregationTable
group by Id
全部回答
- 1楼网友:神也偏爱
- 2021-03-02 15:34
你说呢...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯