学生表Student(Sno,Sname,Ssex,Snation,Spolitical,Sbirth,Scollege,Smajor,Sclass)
课程表Course (Cno,Cname,Credit,Cproperty,Chour,Cterm)
选课表SC(Sno,Cno,Grade)
教师表Teacher(Tno,Tname,Tsex,Tbirth,Ttitle,Tcollege)
授课表TC(Id,Tno,Cno,Sclass,Semester,TimePlace)
供应商表s(sno, sname, city)
零件表p(pno, pname, color, weight)
工程项目表j(jno, jname, city)
供应情况表 spj(sno, pno, jno, qty)
select pname, color, weight
from p
where weight >= 10 and weight <= 20;
select avg(weight)
from p;
select * from p
where pno in
(select pno from spj
where sno = 's3');
select sno, count(distinct pno) classes --classes是起的别名,这里是省略的写法
from spj
group by sno;
select sno, count(distinct pno) classes
from spj
group by sno
having count(distinct pno) > 2;
select * from p
where pname like '螺%';--因为编码的问题,这里可能查出来空表
新增以下环境变量可以解决这个问题。
select pno, count(distinct sno) as snum --这里是起别名完整的写法
from spj
group by pno;
select pname
from p
where pno in
(select pno
from spj
group by pno
having sum(qty) between 1000 and 2000
);
select cname, chour, cterm
from course
where cno in
(select cno
from sc
group by cno having sum(sno) > 60);
select scollege, count(sno)
from student
group by scollege;
select student.sno, sname, sum(credit) as SumCredit
from student
left join sc on sc.sno = student.sno
left join course on course.cno = sc.cno
group by student.sno, sname;
select student.sno, sname, sum(credit) as SumCredit
from student, sc, course
where student.sno = sc.sno and sc.cno = course.cno
group by student.sno, sname;
select cname, student.sname, grade
from student, course, sc, tc, teacher
where student.sno = sc.sno and course.cno = sc.cno and tc.cno = sc.cno and tc.tno = teacher.tno and tname = '吴春燕';
select distinct sname
from student, sc
where student.sno = sc.sno
and sc.sno in
(select sno from sc, course
where sc.cno = course.cno and cname = '中间件技术'
and sno IN
(SELECT sno from sc, course
where sc.cno = course.cno and cname = 'Java EE技术'
)
)
select sname, smajor
from student
where sbirth <= to_date('19940101','YYYYMMDD');
select student.sno, sname
from student, sc
where student.sno = sc.sno
group by student.sno, sname
having count(cno) > 5;
select sname, trunc(months_between(sysdate, sbirth) / 12) as age
from student x
where to_number(to_char(sbirth,'yyyymmdd')) >
(select avg(to_number(to_char(sbirth,'yyyymmdd')))
from student y
where x.scollege = y.scollege
);
select tname
from teacher
where not exists
(select *
from tc
where tno = teacher.tno
);
select *
from student
where sbirth < all
(select sbirth
from student
where scollege = '计算机科学与技术'
);
最近刚学数据库操作,如果有错误或者哪里还有不足,希望大佬可以指出。