zoukankan      html  css  js  c++  java
  • ORACLE1.14-集合

    -- 与数学有关系的集合()

    -- 单条语句

    select * from t_ke

    where ke_name like '%数学%' or ke_name='马克思主义'

     

     

    select * from t_ke where ke_name like '%数学%'

    union all

    select * from t_ke where ke_name='马克思主义'

     

    -->>

    select * from t_ke where ke_name like '%数学%'

    select * from t_ke where ke_name='离散数学'

     

    select * from t_ke

    where ke_name like '%数学%' or ke_name='离散数学'

     

    select * from t_ke where ke_name like '%数学%'

    union all

    select * from t_ke where ke_name='离散数学'

    union all

    select 88 id,'城市建设' ke_name from dual

     

     

    select * from t_ke where ke_name like '%数学%'

    union

    select * from t_ke where ke_name='离散数学'

    union

    select 88 id,'城市建设' ke_name from dual

    create table t_stu2(

       id number primary key,

       user_name varchar2(10),

       sex varchar2(10)

    );

     

    insert into t_stu2 values(1,'小军','男');

    insert into t_stu2 values(2,'小黄','女');

    insert into t_stu2 values(3,'小陈','男');

    insert into t_stu2 values(4,'小姚','女');

    commit

     

    create table t_yigong(

       id number primary key,

       user_name varchar2(10)

    );

     

    insert into t_yigong values(1,'小陈');

    insert into t_yigong values(2,'小姚');

    insert into t_yigong values(3,'小K');

    insert into t_yigong values(4,'小T');

    commit

    select * from t_stu2

    select * from t_yigong

     

    -- 想看看学生中,有那些是义工

    -- 思维1:条件查询

    select * from t_stu2

      where user_name in (select user_name from t_yigong)

     

    -- 想看看义工中,有那些是学生

    -- 思维1:条件查询

    select * from t_yigong

      where user_name in (select user_name from t_stu2)

     

     

    -- 问题未必看交集的名字,只是我们要用到交集这个概念。

    -- 有可能,我查询的内容根本与学生或这义工的名字毫无联系

    -- 学生这个群体,愿意当义工的,女孩子多还是男孩子多?

    select sex,count(1) from t_stu2 where user_name in(

      select user_name from t_stu2

      intersect

      select user_name from t_yigong

    ) group by sex

     

    insert into t_stu2 values(5,'小冰','女');

    insert into t_yigong values(5,'小冰');

    Commit

    -- 学生这个群体,不愿意当义工的,女孩子多还是男孩子多?

    --错误示范(99%大学生会犯的错误)

    select sex,count(1) from t_stu2 where user_name not in(

      select user_name from t_stu2

      intersect

      select user_name from t_yigong

    ) group by sex

    --  not in就是一种排除法

    -- 学习英语A,B,C,D (要排除3个才能得到正确答案)

    -- 对in操作:打开书本,在目录里面查询

    -- 对not in操作:打开书本,800页也需要一页一页看

    select * from t_stu2

     

    select sex,count(1) from t_stu2 where user_name in(

      select user_name from t_stu2

      minus

      select user_name from t_yigong

    ) group by sex

  • 相关阅读:
    http 状态码及含义
    PHP CURL 调用API
    Bootstrap
    JavaScript和快速响应的用户界面
    GitHub配置步骤和简单的git关联
    Git的导入
    java 对象 类 知识点 概览
    java程序执行时,JVM内存
    java区分大小写,使用TAB进行缩进,public类名只能有一个,而且文件名与类名保持一致.
    第六章 进程总结
  • 原文地址:https://www.cnblogs.com/wyj1212/p/8572064.html
Copyright © 2011-2022 走看看