指点成金-最美分享吧

登录

SQL语句:统计指定字段,等于不同值的条数

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了SQL语句:统计指定字段,等于不同值的条数相关的知识,希望对你有一定的参考价值。

参考技术A 方法一:通过group
by
,之后count条数实现。
sql:select
count(1)
from
tablename
group
by
columes;
方法二:通过district函数来直接取出唯一字段,之后统计数量:
sql:select
count(ditrict(columes))
from
tablename;
解释:columes表示的是特殊字段。

SQL 中如何统计某一属性为某个值的记录的条数?

1、创建测试表,

create table test_where(id number, value number);

2、插入测试数据

insert into test_where select round(mod(level,12)), level from dual connect by level < 1000;

commit;

3、查询表中数据,select t.*,rowid from test_where t;

4、编写sql,查询总记录数、以及id等于9的记录数;

select count(*), count(case when id = 9 then 1 end) from test_where t;

参考技术A 那还不简单,稍微变化一下就好咯,假设你需要统计的那个属性列名叫"sx’
select sx , count(*) from table group by sx

输出结果的第一列就是属性值,第2列就是等于这个属性有多少条记录。
参考技术B select count(*) from 表 where 字段="?"追问

就是我要将这一属性等于的各个值的数量,都对应的显示出来

追答

select 字段a,count(*) from 表 group by 字段a

参考技术C 通下

以上是关于SQL语句:统计指定字段,等于不同值的条数的主要内容,如果未能解决你的问题,请参考以下文章