得到一个表里某个字段总条数(过滤重复值)的SQL语句怎样写啊?

比如有表 A 中字段 B,B的值为:

1
1
2
2
3

那么我希望得到不同值的个数为3,也不知我说明白没有。:)

---------------------------------------------------------------

select count(B) from (select distinct B from A)
---------------------------------------------------------------

SELECT COUNT(B) AS X FROM (SELECT DISTINCT B FROM A) DERIVEDTBL

X就是你想要得!
---------------------------------------------------------------

select count(distinct(b)) from a

Published At
Categories with Web编程
Tagged with
comments powered by Disqus