简单查询

内容和主要步骤:

1)创建学生表student、课程表course和选课表SC,并输入数据(注意数据的完整性。);(可以使用实验一中已经建立的表和数据)

2) 对各表中的数据进行不同条件的查询;

a)查询全体学生的学号和姓名

b)查询全体学生的详细记录

c)查询所有选修过课程的学生学号

d)查询考试有不及格的学生学号

e)查询不是信息系(IS)、计算机系(CS)的学生性别、年龄、系别

f)查询选修了4号课的学生学号和成绩,结果按成绩降序排列

g)查询每个课程号和相应的选课人数

h)查询计算机系(CS)的学生姓名、年龄、系别

i)查询年龄18-20岁的学生学号、姓名、系别、年龄;

j)查询姓刘的学生情况

k)查询既选修1号课程,又选修2号课程的学生学号和成绩

l)查询学生的姓名和出生年份(今年2003年)

m)查询没有成绩的学生学号和课程号

n)查询总成绩大于200分的学生学号

o)查询每门课程不及格学生人数

p)查询不及格课程超过3门的学生学号

q)查询年龄在10到19岁之间的学生信息

r)查询全体学生情况,按所在系升序排列,同一个系的学生按年龄降序排列

s)查询选了1号课程的学生平均成绩

t)查询选了3号课程的学生的最高分

u)查询每个同学的总成绩

复杂查询

内容和主要步骤:

1)实验一中的数据为基础

2) 对各表中的数据进行不同条件的连接查询和嵌套查询;

(1)?查询每个学生及其选课情况;

(2)?查询每门课的间接先修课

(3)?将STUDENT,SC进行右连接

(4)?查询有不及格的学生姓名和所在系

(5)?查询所有成绩为优秀(大于90分)的学生姓名

(6)?查询既选修了2号课程又选修了3号课程的学生姓名、学号;

(7)?查询和刘晨同一年龄的学生

(8)?选修了课程名为“数据库”的学生姓名和年龄

(9)?查询其他系比IS系任一学生年龄小的学生名单

(10)?查询其他系中比IS系所有学生年龄都小的学生名单

(11)?查询选修了全部课程的学生姓名

(12)?查询计算机系学生及其性别是男的学生

(13)?查询选修课程1的学生集合和选修2号课程学生集合的差集

(14)?查询李丽同学不学的课程的课程号

(15)?查询选修了3号课程的学生平均年龄

(16)?求每门课程学生的平均成绩

(17)?统计每门课程的学生选修人数(超过3人的才统计)。要求输出课程号和选修人数,结果按人数降序排列,若人数相同,按课程号升序排列

(18)?查询学号比刘晨大,而年龄比他小的学生姓名。

(19)?求年龄大于女同学平均年龄的男同学姓名和年龄

(20)?求年龄大于所有女同学年龄的男同学姓名和年龄

(21)?查询至少选修了95002选修的全部课程的学生号码

(22)?查询95001和95002两个学生都选修的课程的信息

更新查询题目:

1)  应用INSERT,UPDATE,DELETE语句进行更新操作;

a)    插入如下学生记录(学号:95030,姓名:李莉,年龄:18)

b)    插入如下选课记录(95030,1)

c)    计算机系学生年龄改成20

d)    数学系所有学生成绩改成0

e)    把低于总平均成绩的女同学成绩提高5分

f)     修改2号课程的成绩,若成绩小于75分提高5%,成绩大于75时提高

4%(两个语句实现,注意顺序)

g)    删除95030学生信息

h)    删除SC表中无成绩的记录

i)     删除张娜的选课记录

j)     删除数学系所有学生选课记录

k)    删除不及格的学生选课记录

l)     查询每一门课程成绩都大于等于80分的学生学号、姓名和性别,把值送往另一个已经存在的基本表STU(SNO,SNAME,SSEX)中

m)   把所有学生学号和课程号连接追加到新表中

n)    所有学生年龄增1

o)    统计3门以上课程不及格的学生把相应的学生姓名、系别追加到另外一个表中

答案:

1.
SQL> select sno,sname from student;

SNO SNAME
---------- ----------------
     95001 张力
     95002 李丽
     95003 赵海
     95004 张那
     95005 刘晨
     95006 刘丹
     95007 刘立
     95008 王江
     95009 高晓
     95010 张丽

2.SQL> select * from student;

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95001 张力             cs                                       男         
        18                                                                      
                                                                                
     95002 李丽             is                                       女         
        19                                                                      
                                                                                
     95003 赵海             ma                                       男         
        20

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95004 张那             cs                                       女         
        17                                                                      
                                                                                
     95005 刘晨             is                                       男         
        18                                                                      
                                                                                
     95006 刘丹             ma                                       女         
        17

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95007 刘立             cs                                       男         
        21                                                                      
                                                                                
     95008 王江             cs                                       男         
        19                                                                      
                                                                                
     95009 高晓             is                                       男         
        20

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95010 张丽             cs                                       女         
        19                                                                      
                                                                                
SQL> spool off
3SQL> select distinct sno from sc where cno is not null;

SNO                                                                      
----------                                                                      
     95008                                                                      
     95005                                                                      
     95010                                                                      
     95009                                                                      
     95006                                                                      
     95001                                                                      
     95003                                                                      
     95004                                                                      
     95002           
4SQL> select sno from sc where grade<60 or grade is null;

SNO                                                                      
----------                                                                      
     95002                                                                      
     95006                                                                      
     95008    
5.SQL> select ssex,sage,sdept from student where sdept !='is' and sdept!='cs';

SSEX       SAGE SDEPT                                                           
---- ---------- ----------------------------------------                        
男           20 ma                                                              
女           17 ma                                                              
SQL> spool off
6SQL> select sno,grade from sc where cno ='4' order by grade DESC;

SNO      GRADE                                                           
---------- ----------                                                           
     95001         90                                                           
7SQL> select cno,count(cno) from sc group by cno;

CNO COUNT(CNO)                                                           
---------- ----------                                                           
         1          5                                                           
         6          1                                                           
         2          2                                                           
         4          1                                                           
         3          5                                                           
8SQL> select sname,sage,sdept from student where sdept='cs';

SNAME                  SAGE SDEPT                                               
---------------- ---------- ----------------------------------------            
张力                     18 cs                                                  
张那                     17 cs                                                  
刘立                     21 cs                                                  
王江                     19 cs                                                  
张丽                     19 cs                                   
9SQL> select sno,sname,sdept,sage from student where sage between 18 and 20;

SNO SNAME            SDEPT                                          SAGE 
---------- ---------------- ---------------------------------------- ---------- 
     95001 张力             cs                                               18 
     95002 李丽             is                                               19 
     95003 赵海             ma                                               20 
     95005 刘晨             is                                               18 
     95008 王江             cs                                               19 
     95009 高晓             is                                               20 
     95010 张丽             cs                                               19 
10
SQL> select * from student where sname like'刘%';

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95005 刘晨             is                                       男         
        18                                                                      
                                                                                
     95006 刘丹             ma                                       女         
        17                                                                      
                                                                                
     95007 刘立             cs                                       男         
        21                                                                      
                                                                                
11
SQL> select Sno
  2  from SC
  3  where Cno='1' and sno in (select Sno from SC where Cno='2');
12SQL> select sname,(2003-sage) from student;

SNAME            (2003-SAGE)                                                    
---------------- -----------                                                    
张力                    1985                                                    
李丽                    1984                                                    
赵海                    1983                                                    
张那                    1986                                                    
刘晨                    1985                                                    
刘丹                    1986                                                    
刘立                    1982                                                    
王江                    1984                                                    
高晓                    1983                                                    
张丽                    1984                                                    
13
SQL> select sno,cno from sc where grade is null;

SNO        CNO                                                           
---------- ----------                                                           
     95002          3                                                           
     95006          3                                                           
     95008          1     
14
SQL> select sno,sum(grade) as su from sc group by sno having sum(grade)>200;

SNO         SU                                                           
---------- ----------                                                           
     95001        379        
15
SQL> select cno,count(sno) from sc where grade<60 or grade is null group by cno;

CNO COUNT(SNO)                                                           
---------- ----------                                                           
         1          1                                                           
         3          2           
16
SQL> select sno from sc where grade<60 group by sno having count(cno)>=3;
17SQL> select * from student where sage between 10 and 19;

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95001 张力             cs                                       男         
        18                                                                      
                                                                                
     95002 李丽             is                                       女         
        19                                                                      
                                                                                
     95004 张那             cs                                       女         
        17

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95005 刘晨             is                                       男         
        18                                                                      
                                                                                
     95006 刘丹             ma                                       女         
        17                                                                      
                                                                                
     95008 王江             cs                                       男         
        19

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95010 张丽             cs                                       女         
        19                                                                      
                                                                                
18
SQL> select * from student order by sdept,sage desc;

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95007 刘立             cs                                       男         
        21                                                                      
                                                                                
     95010 张丽             cs                                       女         
        19                                                                      
                                                                                
     95008 王江             cs                                       男         
        19

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95001 张力             cs                                       男         
        18                                                                      
                                                                                
     95004 张那             cs                                       女         
        17                                                                      
                                                                                
     95009 高晓             is                                       男         
        20

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95002 李丽             is                                       女         
        19                                                                      
                                                                                
     95005 刘晨             is                                       男         
        18                                                                      
                                                                                
     95003 赵海             ma                                       男         
        20

SNO SNAME            SDEPT                                    SSEX       
---------- ---------------- ---------------------------------------- ----       
      SAGE                                                                      
----------                                                                      
     95006 刘丹             ma                                       女         
        17                                                                      
                                                                                
19SQL> select avg(grade) from sc where cno='3';

AVG(GRADE)                                                                      
----------                                                                      
95.6666667                                                                      
20
SQL> select max(grade) from sc where cno='3';

MAX(GRADE)                                                                      
----------                                                                      
       100                                                                      
21
SQL> select max(grade) from sc where cno='1';

MAX(GRADE)                                                                      
----------                                                                      
       100                                                                      
22
SQL> select avg(grade) from sc where cno='1';

AVG(GRADE)                                                                      
----------                                                                      
      94.5                                                                      
23
SQL> select sno,count(grade) from sc group by sno;

SNO COUNT(GRADE)                                                         
---------- ------------                                                         
     95008            0                                                         
     95005            1                                                         
     95010            1                                                         
     95009            1                                                         
     95006            0                                                         
     95001            4                                                         
     95003            2                                                         
     95004            1                                                         
     95002            1                                                         
SQL> spool off

https://wenku.baidu.com/view/4dd58d7501f69e31433294d2.html

复杂:
(1)SQL> select sno,cno from sc where sno in(select sno from sc group by sno);

SNO        CNO
---------- ----------
     95001          1
     95002          2
     95003          1
     95004          1
     95001          3
     95001          4
     95002          3
     95003          3
     95005          2
     95006          3
     95008          1

SNO        CNO
---------- ----------
     95009          1
     95010          3
     95001          6
(2)
SQL> SELECT course1.cno,course2.cpno
  2  from course course1,course course2
  3  where course1.cpno=course2.cno;

CNO       CPNO
---------- ----------
         1          3
         5
         2
         4          3
(3)
SQL> select student.*,sc.*
  2  from student right join sc on student.sno=sc.sno;

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE        SNO        CNO      GRADE
---------- ---------- ---------- ----------
     95001 张力             cs                                       男
        18      95001          6        100

95001 张力             cs                                       男
        18      95001          4         90

95001 张力             cs                                       男
        18      95001          3         89

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE        SNO        CNO      GRADE
---------- ---------- ---------- ----------
     95001 张力             cs                                       男
        18      95001          1        100

95002 李丽             is                                       女
        19      95002          3

95002 李丽             is                                       女
        19      95002          2         98

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE        SNO        CNO      GRADE
---------- ---------- ---------- ----------
     95003 赵海             ma                                       男
        20      95003          3         98

95003 赵海             ma                                       男
        20      95003          1         99

95004 张那             cs                                       女
        17      95004          1         90

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE        SNO        CNO      GRADE
---------- ---------- ---------- ----------
     95005 刘晨             is                                       男
        18      95005          2         97

95006 刘丹             ma                                       女
        17      95006          3

95008 王江             cs                                       男
        19      95008          1

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE        SNO        CNO      GRADE
---------- ---------- ---------- ----------
     95009 高晓             is                                       男
        20      95009          1         89

95010 张丽             cs                                       女
        19      95010          3        100

SQL>
(4)SQL> select sname,sdept from sc,student where student.sno=sc.sno and grade<60;
(5)

SQL> select sname from student,sc where student.sno=sc.sno group by sname having min(grade)>90;

SNAME
----------------
李丽
刘晨
赵海
张丽
(6)
SQL> select student.sno,sname from student,sc where student.sno=sc.sno and cno='002' and sc.sno in
  2  (select sno from sc where cno='003');

SNO SNAME
---------- ----------------
     95002 李丽
(7)
SQL> select * from student where sage = (select sage from student where sname='刘晨') and sname<>'刘晨';

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95001 张力             cs                                       男
        18
(8)
SQL> select sname,sage from student,sc,course where student.sno=sc.sno and course.cno=sc.cno and cname='数据库';

SNAME                  SAGE
---------------- ----------
张力                     18
赵海                     20
张那                     17
王江                     19
高晓                     20
(9)
SQL> select sno,sname,sdept,sage from student where sage< any(select sage from student where sdept='is') and sdept<>'is';

SNO SNAME            SDEPT                                          SAGE
---------- ---------------- ---------------------------------------- ----------
     95006 刘丹             ma                                               17
     95004 张那             cs                                               17
     95001 张力             cs                                               18
     95008 王江             cs                                               19
     95010 张丽             cs                                               19
SQL>
(10)
SQL> select sno,sname,sdept,sage from student where sage<(select min(sage) from student where sdept='is') and sdept<>'is';

SNO SNAME            SDEPT                                          SAGE
---------- ---------------- ---------------------------------------- ----------
     95004 张那             cs                                               17
     95006 刘丹             ma                                               17
(11)SQL> select sname,sdept from student where not exists (select * from course where not exists(select * from sc where sno=student.sno and cno=course.cno));
(12)
SQL> select * from student where sdept='is' and ssex='男';

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95005 刘晨             is                                       男
        18

95009 高晓             is                                       男
        20
(13)

SQL> select sno from sc where cno ='001' and sno in (select sno from sc where cno<>'002');

SNO
----------
     95001
     95003
     95004
     95008
     95009
(14)
SQL> SELECT distinct cno
  2  from sc
  3  where cno not in
  4  (select cno
  5  from student,sc
  6  where student.sno=sc.sno and sname='李丽' );

CNO
----------
         1
         6
         4
(15)
         4
SQL> select avg(sage) from student,sc where student.sno=sc.sno and cno='003';

AVG(SAGE)
----------
      18.6
(16)
95.6666667
SQL> select cno,avg(grade) from sc group by cno;

CNO AVG(GRADE)
---------- ----------
         1       94.5
         6        100
         2       97.5
         4         90
         3 95.6666667
(17)
SQL> select cno,count(sno) from sc group by cno having count(sno)>3 order by count(sno) asc,cno desc;

CNO COUNT(SNO)
---------- ----------
         3          5
         1          5
(18)
         1          5
SQL> select sname from student where sno>(select sno from student where sname='刘晨') and sage<(select sage from student where sname='刘晨');

SNAME
----------------
刘丹
(19)
SQL> select sname,sage from student where sage>(select avg(sage) from student where ssex='女') and ssex<>'女';

SNAME                  SAGE
---------------- ----------
赵海                     20
刘立                     21
王江                     19
高晓                     20
(20)
SQL> select sname,sage from student where sage>all(select sage from student where ssex='女');

SNAME                  SAGE
---------------- ----------
高晓                     20
赵海                     20
刘立                     21
(21)
SQL> ed
已写入 file afiedt.buf

1  select sno
  2  from sc
  3  where
  4  cno in (SELECT cno from sc where sno='95002')
  5  and sno <>'95002'
  6  group by sno
  7* having count(cno)>=(select count(cno) from sc where sno='95002')
  8  ;
SQL>
(22)
SQL> ed
已写入 file afiedt.buf

1  SELECT course.cno,cname,cpno,credit
  2  from sc,course
  3  where sc.cno=course.cno and
  4  sno='95001' and
  5* sc.cno in (select cno from sc where sno='95002')
SQL> /

CNO CNAME                                          CPNO     CREDIT
---------- ---------------------------------------- ---------- ----------
         3 程序设计                                                     2
SQL>

更新查询
(1)
SQL> insert into student(sno,sname,sage) values('95030','李莉',18);
SQL> select * from student where sname='李莉';

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95030 李莉
        18

SQL>
(2)

SQL> insert into sc values ('95030',1,null);
SQL> select * from sc where sno='95030';

SNO        CNO      GRADE
---------- ---------- ----------
     95030          1
SQL>
(3)
SQL> update student set sage = 20 where sdept='is' ;
SQL> select * from student where sdept='is';

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95002 李丽             is                                       女
        20

95005 刘晨             is                                       男
        20

95009 高晓             is                                       男
        20

SQL>
(4)

SQL> update sc set grade=0 where 'ma' =(select sdept from student where student.sno=sc.sno);
SQL> select * from sc ;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2         98
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95002          3
     95003          3          0
     95005          2         97
     95006          3          0
     95008          1

SNO        CNO      GRADE
---------- ---------- ----------
     95009          1         89
     95010          3        100
     95001          6        100
     95030          1
SQL>
(5)
SQL> update sc set grade=grade+5 where sno in (select student.sno from student,sc where ssex='女' and student.sno=sc.sno and grade<(select avg(grade) from sc));
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2         98
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95002          3
     95003          3          0
     95005          2         97
     95006          3          5
     95008          1

SNO        CNO      GRADE
---------- ---------- ----------
     95009          1         89
     95010          3        100
     95001          6        100
     95030          1
(6)
SQL> update sc set grade=(case when grade<75 then grade*(1+0.05) when grade>75 then grade*(1+0.1) else grade end) where cno='2';
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2        108
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95002          3
     95003          3          0
     95005          2        107
     95006          3          5
     95008          1

SNO        CNO      GRADE
---------- ---------- ----------
     95009          1         89
     95010          3        100
     95001          6        100
     95030          1
(7)
SQL> select * from student;

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95001 张力             cs                                       男
        18

95002 李丽             is                                       女
        20

95003 赵海             ma                                       男
        20

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95004 张那             cs                                       女
        17

95005 刘晨             is                                       男
        20

95006 刘丹             ma                                       女
        17

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95007 刘立             cs                                       男
        21

95008 王江             cs                                       男
        19

95009 高晓             is                                       男
        20

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95010 张丽             cs                                       女
        19

95030 李莉
        18

SQL> delete from student where sno='95030';
SQL> select * from student;

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95001 张力             cs                                       男
        18

95002 李丽             is                                       女
        20

95003 赵海             ma                                       男
        20

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95004 张那             cs                                       女
        17

95005 刘晨             is                                       男
        20

95006 刘丹             ma                                       女
        17

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95007 刘立             cs                                       男
        21

95008 王江             cs                                       男
        19

95009 高晓             is                                       男
        20

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95010 张丽             cs                                       女
        19
(8)
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2        108
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95002          3
     95003          3          0
     95005          2        107
     95006          3          5
     95008          1

SNO        CNO      GRADE
---------- ---------- ----------
     95009          1         89
     95010          3        100
     95001          6        100
SQL> delete from sc where grade is null;
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2        108
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95003          3          0
     95005          2        107
     95006          3          5
     95009          1         89
     95010          3        100

SNO        CNO      GRADE
---------- ---------- ----------
     95001          6        100
(9)
SQL> delete from sc where sno =(select sno from student where sname='张娜');
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2        108
     95003          1          0
     95004          1         90
     95001          3         89
     95001          4         90
     95003          3          0
     95005          2        107
     95006          3          5
     95009          1         89
     95010          3        100

SNO        CNO      GRADE
---------- ---------- ----------
     95001          6        100
SQL> select * from student where sname='张娜';
SQL>
(10)

SQL> delete from sc where sno in(select sno from student where sdept='ma');
SQL> select * from sc;

SNO        CNO      GRADE
---------- ---------- ----------
     95001          1        100
     95002          2        108
     95004          1         90
     95001          3         89
     95001          4         90
     95005          2        107
     95009          1         89
     95010          3        100
     95001          6        100
SQL>
(11)
SQL> delete from sc where grade<60;
(12)
SQL> create table stu
  2  ( SNO   NUMBER(10),
  3    SNAME NVARCHAR2(8) not null,
  4     SSEX  NVARCHAR2(2));
SQL> select sno,sname,ssex into stu from student where sno in(select sno from sc group by sno having min(grade)>80);

(13)
SQL>  Select sc.sno,cno into xinbiao(sno,sname) from student,sc where student.sno=sc.sno;
(14)
SQL> update student set sage =sage+1 ;
SQL> select * from student;

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95001 张力             cs                                       男
        19

95002 李丽             is                                       女
        21

95003 赵海             ma                                       男
        21

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95004 张那             cs                                       女
        18

95005 刘晨             is                                       男
        21

95006 刘丹             ma                                       女
        18

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95007 刘立             cs                                       男
        22

95008 王江             cs                                       男
        20

95009 高晓             is                                       男
        21

SNO SNAME            SDEPT                                    SSEX
---------- ---------------- ---------------------------------------- ----
      SAGE
----------
     95010 张丽             cs                                       女
(15)SQL> Select sname,sdept into XB from student where sno in (select sno from sc where grade<’60’ group by sno having count(grade)>3 );

ORACLE与SQL查询,更新相关推荐

  1. oracle 最大值及其_学习笔记:Oracle优化 SQL查询最大值 最小值时的优化方法案例...

    天萃荷净 select max(id),min(id) from table优化,分享开发DBA需求,在SQL语句查询最大值.最小值数据时的优化方式案例 1.查看数据库版本 SQL> selec ...

  2. oracle中sql查询

    oracle中sql查询 一.查询 别名 拼接 nvl替换null值 distinct数据去重 修改列宽(控制sqlplus) 2.排序order by 3.查询条件where 3.函数 单行函数 聚 ...

  3. Oracle数据库SQL查询结果去重——ROW_NUMBER() OVER

    完整SQL selectcxsj,zs,djjg,row_flag from (selectplcx.QUERY_START_DATE || ' 至 ' || plcx.QUERY_END_DATE ...

  4. Oracle提高SQL查询效率where语句条件的先后次序

    (1)选择最有效率的表名顺序(只在基于规则的优化器中有效): Oracle的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处 ...

  5. oracle数据库sql查询,oracle数据库中常用经典SQL查询

    2010-06-03 14:25:15 来自 --1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_ ...

  6. oracle中sql查询增加自增序列号

    如果我们需要在oracle中查询一系列数据,但是需要对查询出来的数据有一个自增的序列号,方便后续的处理的话,我们可以利用rownum 比如有table A 我们可以这么写sql select a.*, ...

  7. Oracle中SQL查询字段值为空时,指定默认值

    一.实现效果 实现设备字段有值显示[加工]否则显示[未加工] 二.Oracle中NVL 2.1.NVL函数功能介绍 NVL 是Oracle的函数,功能是实现空值的转换,如果fieldName为NULL ...

  8. oracle基本SQL查询(上)

    oracle数据库 oracle数据库的概念 平常所说的oracle 或 oracle 数据库指的是oracle数据库管理系统.oracle数据库管理系统是管理数据库访问的计算机软件,它由oracle ...

  9. oracle:sql查询

    最近遇到一些查询,自己还不是能保证一口气就写对,经过和好友一起研究,有一两个比较好的思路,尤其是最后两个查询,值得深思.为纪念这一丁丁进步和思维的一小步跨越,现记录如下: --1.查询所有同学的学号. ...

最新文章

  1. 构建 编译和运行Urho3D工程
  2. 循环神经网络(RNN)原理通俗解释
  3. NIO详解(二): BIO 浅谈 同步 异步与阻塞 非阻塞
  4. 谈谈NITE 2与OpenCV结合的第二个程序(提取人体骨骼坐标)
  5. 异或运算_专题 | 异或运算的一些应用
  6. 深度学习中的激活函数与梯度消失
  7. C#调用Python模块
  8. Gartner发布云产品评估报告:阿里云计算能力全球第一
  9. thinkphp 内部函数 D()、F()、S()、C()、L()、A()、I()
  10. mysql三高教程(二):2.7 如何约束数据
  11. 页面图片中间有条线----解决
  12. 在ORACLE產生001,002的流水號
  13. magento url rewrite规则
  14. H3C Comware平台的优势
  15. 360n4刷android8.1,【从此,任何人都可以刷N4】关于系统降级===线刷方法,我也说两句吧。...
  16. 计算机辅助遥感制图的基本过程,南京信息工程大学2018年遥感原理与应用考研初试大纲...
  17. 手机长度px值_px和厘米怎么换算?
  18. EcShop二次开发学习方法和Ecshop二次开发必备基础
  19. 电子知识|电源管理芯片
  20. CCF推荐会议(人工智能与模式识别)

热门文章

  1. 中望3D2022 缝合
  2. js 创建函数getMax,传递3个参数,返回三个数字中的最大值。
  3. 联想乐Phone中关村惨遭“机卡分离”销售
  4. 基于TNEWS‘ 今日头条中文新闻(短文本)分类
  5. Nabble让我1分钟轻松建立自己的论坛
  6. iPhone 11 Pro Max 拆解
  7. 三星android p公测,三星独占时间到,Android平台《堡垒之夜》开放公测
  8. 用计算机拆分字体,轻松实现Word文字分家(即打散文字,拆偏旁部首) -电脑资料...
  9. Json在Qt中的使用
  10. css定位相关知识点