34,576
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据: #table1
if object_id('tempdb.dbo.#table1') is not null drop table #table1
create table #table1 (号码 varchar(1),件数 int,金额 int)
insert into #table1
select 'a',2,1 union all
select 'a',2,2 union all
select 'a',2,5 union all
select 'b',1,2 union all
select 'b',1,1
select count(distinct 号码),sum(件数),Sum(金额)
from (
select 号码,sum(distinct 件数) 件数,sum(金额) 金额
from #table1
group by 号码
) t
(5 行受影响)
----------- ----------- -----------
2 3 11
(1 行受影响)
--> 测试数据: #table1
if object_id('tempdb.dbo.#table1') is not null drop table #table1
create table #table1 (号码 varchar(1),件数 int,金额 int)
insert into #table1
select 'a',1,1 union all
select 'a',1,2 union all
select 'a',1,5 union all
select 'b',1,2 union all
select 'b',1,1
select count(distinct 号码),sum(件数),Sum(金额)
from (
select 号码,sum(distinct 件数) 件数,sum(金额) 金额
from #table1
group by 号码
) t
----------- ----------- -----------
2 2 11
(1 行受影响)
SELECT COUNT(DISTINCT(col1)),SUM(DISTINCT(col2)),SUM(col3)
FROM table1
--> 测试数据: #table1
if object_id('tempdb.dbo.#table1') is not null drop table #table1
create table #table1 (号码 varchar(1),件数 int,金额 int)
insert into #table1
select 'a',2,1 union all
select 'a',2,2 union all
select 'a',2,5 union all
select 'b',1,2 union all
select 'b',1,1
select count(distinct 号码) 号码,sum(distinct 件数) 件数,sum(金额) 金额
from #table1
号码 件数 金额
----------- ----------- -----------
2 3 11
(1 行受影响)
还是错了,
select count(distinct 号码) 号码,sum(distinct 件数) 件数,sum(金额) 金额
from [Table]
select count(distinct 号码) 票数,count(distinct 金额) 件数,sum(金额) 金额
from tb
?select count(distinct 号码) 号码,count(distinct 件数) 件数,sum(金额) 金额
from [Table]
select sum(distinct 号码) 号码,sum(distinct 件数) 件数,sum(金额) 金额
from [Table]