例表如下
col1 col2 col3
1 2 3
1 4 5
2 2 3
3 6 2统计col1列的 结果要如下
3select count(*)from table group by col1结果是
2
1
1我要的结果是3
怎么写 谢谢!!!
col1 col2 col3
1 2 3
1 4 5
2 2 3
3 6 2统计col1列的 结果要如下
3select count(*)from table group by col1结果是
2
1
1我要的结果是3
怎么写 谢谢!!!
from tb
-- Author:Flystone
-- Version:V1.001
-- Date:2008-09-04 16:44:33
-------------------------------------- Test Data: ta
If object_id('ta') is not null
Drop table ta
Go
Create table ta(col1 int,col2 int,col3 int)
Go
Insert into ta
select 1,2,3 union all
select 1,4,5 union all
select 2,2,3 union all
select 3,6,2
Go
--Start
Select count(distinct col1) from ta
--Result:
/*
-----------
3(所影响的行数为 1 行)*/
--End
select count(distinct col1) from tb