SQL语句如何求不同值的个数

cgd0282 2006-03-18 12:30:27

SELECT COUNT(DISTINCT A)

FROM Table

求出不同A的个数

表table : A B
fd XX
fd jj
gf kk
我现在想要求出A字段fd的有两条,gf的有一条.也就是要结果为:
A count
fd 2
gf 1
有没办法?
...全文
360 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rivery 2006-03-18
  • 打赏
  • 举报
回复
上面字段写错了。
select A,count(*)
from table
group by A
rivery 2006-03-18
  • 打赏
  • 举报
回复
select fd,count(*)
from table
group by A
cgd0282 2006-03-18
  • 打赏
  • 举报
回复
可以了.
aniude 2006-03-18
  • 打赏
  • 举报
回复

a count
---- -----------
fd 2
gf 1

(所影响的行数为 2 行)
aniude 2006-03-18
  • 打赏
  • 举报
回复
create table tb
(
a char(2),
b char(2)
)
insert into tb select 'fd','xx'
union all select 'fd','jj'
union all select 'gf','kk'
select a,[count]=(select count(a) from tb tb2 where tb.a=tb2.a group by a) from tb group by a

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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