oracle 统计语句 与常见函数的归纳(未完待续)

一、统计语句

1. count

count(*)与count(0)语句的区别:

count(*)统计所有数量 count(0)统计第一列不为空的

2. 两个统计量的减法

select
(select count(*) from defect)-(select count(*) from defect where cljg like '%合格%' and cljg not like '%不合格%') as count
from dual 

3. min、max、常见数学函数的使用

select min(pval),max(pval),round(avg(pval),5) from hvm_data_dga .

round(avg(pval),5) 使数值小数点后按照四舍五入保留5位。

二、常见函数的使用

2.1 instr()函数使用

pid:1001-01-01

instr(real_data.pid,'-',1,1)):返回从左边开始第一次出现‘-’的位置。
instr(real_data.pid,'-',-1,1)):返回从右边开始第一次出现‘-’的位置。

2.2 string类型字段截取函数substr()

例,查询表中name字段从第5个字符以后的字符串。

select distinct substr(name,5) from hvm_cfg_data where stationid='12010013'

查询表中name字段从第5个字符开始2个字符的字符串。

select distinct substr(name,5,2) from hvm_cfg_data where stationid='12010013'

参考文章

oracle Count(0)-Count(0)

instr()函数使用

oracle string类型字段截取函数substr()

原文地址:https://www.cnblogs.com/arxive/p/5959157.html