zoukankan      html  css  js  c++  java
  • 数据库组合查询练习1

    drop table stu;
    drop sequence seq_stu;
    create sequence seq_stu;
    create table stu(
     sid number(5) primary key,
     sname varchar2(10),
     ssex varchar2(2) default '男',
     sage number(3),
     sdept number(2) 
    );
    insert into stu values(seq_stu.nextval,'tom','男',21,1);
    insert into stu values(seq_stu.nextval,'lily','女',22,1);
    insert into stu values(seq_stu.nextval,'tony','男',19,1);
    insert into stu values(seq_stu.nextval,'sandy','女',20,2);
    insert into stu values(seq_stu.nextval,'tom','男',21,2);
    insert into stu values(seq_stu.nextval,'lily','女',23,2);
    insert into stu values(seq_stu.nextval,'小明','男',22,3);
    insert into stu values(seq_stu.nextval,'小丽','女',24,3);
    commit;
    select * from stu;
    
    --select distinct sname from stu;
    --重复数据只显示一条
    select * from stu where sid in (select min(sid) from stu group by sname);
    --删除重复的数据
    --delete from stu where sid not in (select min(sid) from stu group by sname);
    
    drop table temptbs;
    drop sequence seq_tbs;
    create sequence seq_tbs;
    create table temptbs(
     id number(5) primary key,
     name varchar2(10),
     value varchar2(10)
    );
    insert into temptbs values(seq_tbs.nextval,'a','pp');
    insert into temptbs values(seq_tbs.nextval,'a','pp');
    insert into temptbs values(seq_tbs.nextval,'b','ii');
    insert into temptbs values(seq_tbs.nextval,'b','pp');
    insert into temptbs values(seq_tbs.nextval,'b','pp');
    insert into temptbs values(seq_tbs.nextval,'c','pp');
    insert into temptbs values(seq_tbs.nextval,'c','pp');
    insert into temptbs values(seq_tbs.nextval,'c','ii');
    insert into temptbs values(seq_tbs.nextval,'d','ii');
    commit;
    select * from temptbs;
    --删除重复数据
    delete from temptbs where id in (select min(id) from temptbs group by name);
    --只显示重复数据
    select * from temptbs where name in (select name from temptbs group by name,value having count(*)>1);
    --只显示不重复数据
    select * from temptbs where name in (select name from temptbs group by name having count(*)=1);

  • 相关阅读:
    apply call this arguments caller callee
    JavaScript 小刮号
    asp.net底层http管道
    JavaScript 使用方括号([])引用对象的属性和方法 createDelegate
    MSIL条件跳转(简单注释)
    微软MVP手把手教你如何修改.NET Framework
    简单操作IL文件
    Remoting入门实例
    AutoResetEvent和ManualResetEvent用法示例
    AutoResetEvent和ManualResetEvent用法
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537383.html
Copyright © 2011-2022 走看看