# 怎么计算纪录总数？（不好意思，暂时没有分，晚上回去绝对加上！）

a sh
a sz
a hn
b bj
b sh

a sh 3
a sz 3
a hn 3
b bj 2
b sh 2

...全文
96 点赞 收藏 8

8 条回复

windy1 2007-11-29
ls ,谢谢，不过出来的结果是所有的数据总数！

-狙击手- 2007-11-29
``````update t
set totalnumber = (select count(1) from table where t.name = name)
from table t``````

-狙击手- 2007-11-29
``````update t
set totalnumber = (select count(1) from t where t.name = name)
from table t``````

JL99000 2007-11-29

issacp 2007-11-29
--try
create table t ([name] varchar(20),[add] varchar(20))
go

insert into t values('a','sh')
insert into t values('a','sz')
insert into t values('a','hn')
insert into t values('b','bj')
insert into t values('b','sh')

select a.[name],a.[add],b.totalnumber from t a left join (select [name],count([name]) [totalnumber ] from t group by [name]) b on a.[name]=b.[name]

drop table t

issacp 2007-11-29
--try
create table t ([name] varchar(20),[add] varchar(20))
go

insert into t values('a','sh')
insert into t values('a','sz')
insert into t values('a','hn')
insert into t values('b','bj')
insert into t values('b','sh')

select a.[name],a.[add],b.totalnumber from t a left join (select [name],count([name]) [totalnumber ] from t group by [name]) b on a.[name]=b.[name]

drop table t

issacp 2007-11-29
--try
create table t ([name] varchar(20),[add] varchar(20))
go

insert into t values('a','sh')
insert into t values('a','sz')
insert into t values('a','hn')
insert into t values('b','bj')
insert into t values('b','sh')

select a.[name],a.[add],b.totalnumber from t a left join (select [name],count([add]) [totalnumber ] from t group by [name]) b on a.[name]=b.[name]

drop table t

3.2w+

MS-SQL Server相关内容讨论专区