数据库-select查询语句

数据库-select查询语句表结构如下:学生表:Student学生表(学号,姓名,性别,年龄,组织部门)       Course 课程表(编号,课程名称)       Sc 选课表(学号,课程编号,成绩)(1).写一个SQL语句,查询选修了’计算机原理’的学生学号和姓名select 学号,姓名from Student where 学号=

大家好,又见面了,我是你们的朋友全栈君。

1.表结构如下:
学生表:Student 学生表 (学号,姓名,性别,年龄,组织部门)
              Course 课程表 (编号,课程名称)
              Sc 选课表 (学号,课程编号,成绩)
(1).写一个SQL语句,查询选修了’计算机原理’的学生学号和姓名
select  学号,姓名 from  Student  where  学号  in
   (select 学号 from Sc where 课程编号 in
          (select  编号 from Course where 课程名称=’计算机原理’
  )
   );
(2).写一个SQL语句,查询’周星驰’同学选修了的课程名字
select 课程名称 from Course where 编号 in
  (select 课程编号 from Sc where 学号=
    (select 学号 from Student where 姓名=’周星驰’
     )
   );
(3).写一个SQL语句,查询选修了5门课程的学生学号和姓名
select 学号,姓名 from Student s join
     (select 学号,count(*) from Sc group by 学号 having count(*) =5)  t
     on (s.学号=t.学号);

2.

有一个职工表employee(eno,ename,esex,deptno,sal),

其中eno代表职工号,数值型(整数),长度为8,eno为student表的主键;ename代表职工姓名,字符型,长度为10;esex代表性别,取值仅为“男”或者“女”;deptno代表部门号,数值型(整数),非空,长度为6;sal是工资

1) :创建表

create table emp(

enonumber(8),

ename     varchar2(10),

esex        varchar2(10),

deptno    number(6),

sal          number(20),

constraint c_esex check(esex in (‘男’,’女’)),

primary key(eno)

)

2):查询姓张的员工

select ename from emp where ename like ‘张%’;

3):查询每个部门员工的人数

select count(*) from emp group by deptno;

4):工资不等于1000的员工的人数

select count(*)  from  emp where sal<>1000;

5):编写存储过程:当sal>1000是工资涨200;当sal>2000是工资涨1000;其他的涨150;

create or replace procedure p is

cursor c is select * from emp for update;

begin

for v_emp in c loop

if(v_emp.sal>1000 and v_emp.sal<=2000) then

update emp set sal=sal+200 where current of c;

elsif (v_emp.sal>2000) then

update emp set sal=sal+1000  where current of c;

else  update emp set sal=sal+150 where current of c;

end if;

       end loop;

 commit;

end;


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139907.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号