zoukankan      html  css  js  c++  java
  • 20181114教学sql

    --精确查找:查询水表编号为30408的业主记录
    SELECT * FROM T_OWNERS WHERE WATERMETER = '30408'
    --模糊查询:查询业主名称包含'刘'的业主记录
    SELECT * FROM T_OWNERS WHERE NAME LIKE '%刘%'
    --AND运算符:查询业主名称包含'刘'的并且门牌号包含5的业主记录
    SELECT * FROM T_OWNERS WHERE NAME LIKE '%刘%' AND HOUSENUMBER LIKE '%5%'
    --or运算符:查询业主名称包含'刘'的或者门牌号包含5的业主记录
    select * from t_owners where name like '%刘%' or housenumber like '%5%'
    --and与or混合使用:查询业主名称包含'刘'的或者门牌号包含5的业主记录,并且地址编号为3的记录
    select * from t_owners where (name like '%刘%' or housenumber like '%5%') and addressid = 3
    --范围查询:查询台账记录中用水字数大于等于10000并且小于等于20000的记录
    select * from t_account where usenum>=10000 and usenum<=20000
    select * from t_account where usenum between 10000 and 20000
    --空值查询:查询t_pricetable 表中maxnum为空的记录
    select * from t_pricetable where maxnum is null
    --不为空
    select * from t_pricetable where maxnum is not null
    --去重:查询业主表中的地址ID 不重复显示
    select distinct addressid from t_owners
    
    --聚合统计
    --求和sum:统计2012年所有用户的用水量总和
    select sum(usenum) from t_account where year = '2012'
    --求平均数avg:统计2012年所有用水量的平均值
    select avg(usenum) from t_account where year = '2012'
    --求最大值max:统计2012年最高用水量
    select max(usenum) from t_account where year = '2012'
    select min(usenum) from t_account where year = '2012'
    --统计记录数count:统计业主类型ID为1的业主记录
    select count(*) from t_owners where ownertypeid = 1
    --分组聚合:按区域分组统计水费合计数
    select areaid,sum(money) from t_account group by areaid
    --分组后条件查询having:查询水费合计大于16900的区域及水费合计
    select areaid,sum(money) from t_account group by areaid having sum(money)>16900
    
    --集合运算
    --并集(包含重复记录)
    select * from t_owners where id>5
    union all
    select * from t_owners where id<8
    select * from t_owners where id>5
    union
    select * from t_owners where id<8
    --交集
    select * from t_owners where id>5
    intersect
    select * from t_owners where id<8
    --差集
    select * from t_owners where id>5
    minus
    select * from t_owners where id<8
    select * from t_owners where id<8
    minus
    select * from t_owners where id>5
    
    --序列
    --创建简单序列
    create sequence seq_test1;
    --查询序列的下一个值
    select seq_test1.nextval from dual;
    --查询序列的当前值
    select seq_test1.currval from dual;
    --创建一个有最大值的非循环序列
    create sequence seq_test2 maxvalue 5;
    select seq_test2.nextval from dual;
    --自定义增长值
    create sequence seq_test3
    increment by 10
    start with 10
    maxvalue 100
    select seq_test3.nextval from dual;
    --有最小值的序列
    create sequence seq_test4
    increment by 10
    start with 10
    minvalue 5
    maxvalue 100
    select seq_test4.nextval from dual;
    --循环序列
    create sequence seq_test5
    increment by 10
    start with 10
    minvalue 10
    maxvalue 210
    cycle
    select seq_test5.nextval from dual;
    
    --同义词
    --创建私有同义词
    create synonym owner for t_owners;
    select * from owner
    select * from wateruser.t_owners
    --创建公有同义词
    create public synonym owner2 for t_owners;
    select * from owner2
  • 相关阅读:
    dudu把博客园搞成中国的stackoverflow就牛x大了
    微雨燕双飞,落花人独立 。是什么意思
    Fill Value To List : XML Bean Property « Spring « Java
    Ruby SQLite GUI
    工作流现状
    Windows Phone开发(32):路径之PathGeometry
    《论道HTML5》内容技术分享活动
    Windows Phone开发(30):图形
    wp7资源调用
    Cocos2dx win7 + vs2010 配置图文详解 .
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9960468.html
Copyright © 2011-2022 走看看