1、SQL AVG 函数 :
AVG 函数返回数值列的平均值。NULL 值不包括在计算中。
例如:现在,我们希望找到 OrderPrice 值高于 OrderPrice 平均值的客户。我们使用如下 SQL 语句:
select customer from orderswhere orderprice > ( select avg(orderprice) from orders )
3、rownum 函数:
ROWNUM是一种伪列,它会根据返回记录生成一个序列化的数字。系统是按照记录插入时的顺序给记录排的号。rownum都是从1开始,但是1以上的自然数在rownum做等于判断是时认为都是false条件,所以无法查到rownum = n(n>1的自然数)。
select rownum ,yc_id,yc_personid,yc_cstno from yc_user where rownum <20 ; 可以
select rownum ,yc_id,yc_personid,yc_cstno from yc_user where rownum >20 ; 不可以
select * from(select rownum r ,yc_id,yc_personid,yc_cstno from yc_user ) where r>20 ;可以
select * from(select rownum r ,yc_id,yc_personid,yc_cstno from yc_user where rownum <50) where r>20 ;可以 20到50的
select rownum r ,yc_id,yc_personid,yc_cstno from yc_user order by yc_personid 与 下面不同
select rownum ,yc_id,yc_personid,yc_cstno (select yc_id,yc_personid,yc_cstno from yc_user order by yc_personid )