zoukankan      html  css  js  c++  java
  • Oracle数据库之查询

    一、单表简单查询:

    1、

    select * from scott.emp

    2、去重:

    --去除重复记录
    
    select distinct  ssex from java0322;
    select distinct  (ssex) from java0322;

    3、别名:

    --给指定字段指定别名
    select ssid as 编号 ,sname as 姓名 from java

    4、排序:

    --排序 倒序 desc
    select * from java0322 order by ssid desc;

    5、模糊查询:

    --模糊查询
    select * from java0322 where sname like '___';
    select * from java0322 where sname like '%四%';

    二、多表连接查询:

    1、交叉连接:若查询共有字段,需要制定该字段来自哪个表格;-----自然连接

    --内连接
    select * from java0322 join sclass on java0322.cid =sclass.cid;
    -- 给表起别名
    select * from java0322 a join sclass b on a.cid = b.cid;

    2、外连接:

    --左外连接(左边的全部)
    select * from sclass  a left join java0322 b on a.cid =b.cid;
    
    --右外连接(右表的全部)
    select * from java0322 a right join sclass b on a.cid =b.cid;
    
    --全外连接
    
    select * from sclass a full join java0322 b on a.cid = b.cid;

    三、分组聚合:

    1、group by:

    -- 查询男女各多少(按性别分组后查询所有,然后再查个数)
    select ssex,count(*) from java0322 group by ssex;

     2、

    -- 查询性别大于1 的性别
    select ssex from java0322 group by ssex having count(*)>1;

    where 放在group 之前,分组之后条件用having;

    四、子查询:

    -- 子查询--查询性别为女的学生所在的班级
    select cname from sclass where cid in (select cid from java0322 where ssex='');
    --查询阳光班的所有男同学的地址
    select saddress from java0322 where ssex =''and cid in(select cid from sclass where cname='阳光班');
    
    select saddress from java0322 a join sclass b on a.cid = b.cid where ssex='' and cname='阳光班';
    
    select * from (select sclass.cid,cname,ssid,sname from sclass join java0322 on java0322.cid = sclass.cid)

    1、分页:

    --分行---查询第2条
    select * from(select rownum as num,sclass.cid,cname,ssid,sname from sclass join java0322 on java0322.cid = sclass.cid) where num >1 and num<3;
  • 相关阅读:
    leetcode-----5. 最长回文子串
    leetcode-----4. 寻找两个正序数组的中位数
    leetcode-----3. 无重复字符的最长子串
    leetcode-----2. 两数相加
    leetcode-----1. 两数之和
    leetcode-----第 26 场双周赛
    leetcode-----104. 二叉树的最大深度
    leetcode-----103. 二叉树的锯齿形层次遍历
    leetcode-----102. 二叉树的层序遍历
    数据管理必看!Kendo UI for jQuery过滤器的全球化
  • 原文地址:https://www.cnblogs.com/21-forever/p/11263658.html
Copyright © 2011-2022 走看看