sql 从查询结果中查询记录数

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:41:17
例如有一个表age,只有一个字段age,字段值分别为
21
22
22
23
24
24
我怎么写一个sql能够查询有不同的值的记录数

SELECT DISTINCT * FROM AGE

select distinct count(*) from table

select count(distinct(age)) from Age

select count(distinct t1.age) from age t1, age t2 where t1.age <> t2.age

如果你想查所有的不同的记录,可以使用sql:
select distinct(age) from age;
这样可以查询出所有的不重复的记录。

如果你想查询这个不同的age一共有多少个,可以使用sql
select count(distinct(age)) from age;
这样就可以查到一共有多少个不同的age的值。

sselect age, count(age)
from dbo.Table_1
group by age;