sql语句统计数量
1. sql语句统计数量,统计一个字段的值的数量
select type,count(*) as 总数量,
sum(case when level='一级' then 1 else 0 end) as 一级,
sum(case when level='二级' then 1 else 0 end) as 二级,
sum(case when level='三级' then 1 else 0 end) as 三级
from table group by type
楼上的应该改改吧
2. sql统计语句
sql语言诞生有一段时间了,里面有一些自带的很方便的函数,对于操作数据库来说是非常方便的,下面就介绍几种统计。
3. SQL怎么统计个数
不同数据库的系统表可能不一样,比如informix就是systables
的
tabname。
informix数据库:
统计个数:
select
count(*)
from
systables
where
tabname
like
'%abc%'
查看表:
select
tabname
from
systables
where
tabname
like
'%abc%'
其他数据库的话,系统表可能是sysobjects,对应的列可能也有不同,看你的情况改吧。
4. SQL语句 统计部分仓库数量
指定要统计的仓库名称
select count(数量) from (select * from tableName where 仓库名称 in ('仓1','仓2','仓3'));
不指定名称
select count(数量) from tableName where rownum<=num; ps:num就是要查几个仓库,可以当参数传入, 上面的仓1 仓2 也可以当参数传入
5. SQL怎么统计个数
方法一:
SELECT SUM(正确数)+SUM(错误数) AS 总记录数,SUM(正确数),SUM(错误数)
FROM (
SELECT COUNT(1) 正确数,0 错误数
FROM TB
WHERE STATUS=1
UNION ALL
SELECT 0 正确数,COUNT(1) 错误数
FROM TB
WHERE STATUS=0) a
方法二:
select count(1)总记录数,sum(case when status=1 then 1 else 0 end)正确数,sum(case when status=0 then 1 else 0 end) 错误数 from T
6. 如何统计SQL中某字段总数和符合某条件的数量
输入代码
select 名称
,count(*) as 总数量
,count(case when 类型='A' then 类型 else null end) as 类型为A的数
from 表名
group by 名称。
就可以统计SQL中某字段总数和符合某条件的数量。
7. sql语句统计数量 统计一个字段出现的数量
1、创建测试表,
create table test_stu(id number, u_name varchar2(20), subject varchar2(20));
create table test_subj(id number, subject varchar2(20));