Selaa lähdekoodia

testing some stuff, made changes for syntax. referencing style for parent queries is not working i think

tsdedhar 6 vuotta sitten
vanhempi
commit
0f6b11a149
2 muutettua tiedostoa jossa 30 lisäystä ja 27 poistoa
  1. 29 27
      a2/a2.sql
  2. 1 0
      a2/test.sql

+ 29 - 27
a2/a2.sql

@@ -7,11 +7,11 @@ name “computer science”.
 */
 select distinct sname, snum from student where year = 2 and snum in
 (
-  select snum from mark m1 where grade < 65 and deptcode = "CS" and snum in
+  select snum from mark m1 where grade < 65 and deptcode = 'CS' and snum in
   (
-    select snum from mark where grade < 65 and deptcode = "CS" and snum != m1.snum
+    select snum from mark where grade < 65 and deptcode = 'CS' and snum != m1.snum
   )
-)
+);
 
 /*
 The number and name of professors who are not in the pure math (PM)
@@ -19,24 +19,25 @@ department, and who are teaching CS245 for the first time.
 */
 select distinct pnum, pname from professor where deptcode not in
 (
-  select deptcode fromm department where deptname = "PM"
+  select deptcode from department where deptname = 'PM'
 ) and pnum in
 (
-  select pnum from class where deptcode = "CS" and cnum = 245 and term = 1185
+  select pnum from class where deptcode = 'CS' and cnum = 245 and term = 1185
 ) and pnum not in
 (
-  select pnum from class where deptcode = "CS" and cnum = 245 and term != 1185
-)
+  select pnum from class where deptcode = 'CS' and cnum = 245 and term != 1185
+);
 
 /*
 The number, name and year of each student who has obtained a grade in
 CS240 that is within 3 marks of the highest ever grade recorded for that
 course.
+-- Got an error for having not the same # of args on the >= (i think). ACTUALLY THE ISSUE IS WITH AN "=" specifically
 */
 select distinct snum, sname, year from student where snum in
 (
-  select snum, grade from mark where deptcode = "CS" and cnum = 240 and grade >= ((select grade from mark where deptcode = "CS" and cnum = 240 order by grade desc limit 1) - 3)
-)
+  select snum, grade from mark where deptcode = 'CS' and cnum = 240 and grade >= ((select grade from mark where deptcode = 'CS' and cnum = 240 order by grade desc limit 1) - 3)
+);
 
 /*
  The number and name of students who have completed two years, who
@@ -44,9 +45,10 @@ have a final grade of at least 85 in every computer science course that
 they have taken, and who have always been taught by a professor in the
 computer science (CS) department.
 */
+-- another issue with an unbalanced = statement
 select distinct snum, sname from student where year > 2 and snum not in
 (
-  select snum, grade from mark where deptcode = "CS" and grade < 85
+  select snum, grade from mark where deptcode = 'CS' and grade < 85
 ) and snum not in
 (
   select e.snum, e.deptcode, e.cnum, e.term, e.section from enrollment e where exists
@@ -54,22 +56,22 @@ select distinct snum, sname from student where year > 2 and snum not in
     select c.pnum, c.deptcode, c.cnum, c.term, c.section from class c where
     c.deptcode = e.deptcode and c.cnum = e.cnum and c.term = e.term and c.section = e.section and c.pnum not in
     (
-      select pnum from professor where deptcode != "CS"
+      select pnum from professor where deptcode != 'CS'
     )
   )
-)
+);
 
 /*
  A sorted list of all departments who do not have a professor currently
 teaching a course offered by a different department.
 */
-select deptname as prof_dept from department where deptcode not in
+select deptname from department where deptcode not in
 (
-  select deptcode as old_dept, pnum as old_pnum from professor where pnum in
+  select p.deptcode, p.pnum from professor p where pnum in
   (
-    select pnum from class where term = 1185 and deptcode != old_dept and pnum = old_pnum
+    select pnum from class where term = 1185 and deptcode != p.deptcode and pnum = p.pnum
   )
-) order by deptname
+) order by deptname;
 
 /*
 For each pair of classes for the same course that were taught in the same
@@ -101,7 +103,7 @@ select
 c1.cnum, c1.term, c1.pnum, c1.pname, c1.deptcode, c1.section, c1.pnum,
 c2.cnum, c2.term, c2.pnum, c2.pname, c2.deptcode, c2.section, c2.pnum
 from combineTable c1, combineTable c2
-where c1.term = c2.term and c1.deptcode = c2.deptcode and c1.cnum = c2.cnum and c1.pnum != c2.pnum
+where c1.term = c2.term and c1.deptcode = c2.deptcode and c1.cnum = c2.cnum and c1.pnum != c2.pnum;
 
 /*
 Pairs of distinct professors such that whenever the first one teaches a class
@@ -121,7 +123,7 @@ select pnum, pname, pnum2, pname2 from professor, (select pnum as pnum2, pname a
       select pnum from class where deptcode = c.deptcode and cnum = c.cnum and term = c.term and pnum != c.pnum
     )
   )
-)
+);
 
 -- NOW CAN USE AGGREGATION
 
@@ -131,7 +133,7 @@ course. Also, include only those course numbers for courses with a total
 enrollment count among the three lowest such counts.
 */
 -- Not sure if this will return an error, or 3 rows per old.deptcode, old.cnum since the 3rd parameter (the subquery) has 3 rows
-select old.deptcode, old.cnum, (select count(*) from enrollment where deptcode = old.deptcode and cnum = old.cnum group by deptcode, cnum order by count(*) asc limit 3) from class old
+select old.deptcode, old.cnum, (select count(*) from enrollment where deptcode = old.deptcode and cnum = old.cnum group by deptcode, cnum order by count(*) asc limit 3) from class old;
 
 /*
 The percentage of professors in pure math who have always taught no
@@ -139,14 +141,14 @@ more than a single course in any given term. (Note that a percentage
 should be a number between 0 and 100.)
 */
 
-select (select count(*) from professor p where deptcode = "PM" and pnum in
+select (select count(*) from professor p where deptcode = 'PM' and pnum in
 (
   select c.pnum, c.deptcode, c.cnum, c.term, c.section from class c where c.pnum = p.pnum and c.pnum not in
   (
     select c1.pnum, c1.deptcode, c1.cnum, c1.term, c1.section from class c1 where pnum = p.pnum and c1.term = c.term and (c1.deptcode != c.deptcode or c1.cnum != c.cnum)
   )
 ))
-/ (select count(*) from professor where deptcode = "PM") as percentage
+/ (select count(*) from professor where deptcode = 'PM') as percentage;
 
 /*
 The number of different third or fourth year students in each section of
@@ -165,15 +167,15 @@ select (select pname from professor where pnum = c.pnum), c.pnum, c.cnum, c.term
   ) and deptcode = c.deptcode and cnum = c.cnum and term = c.term and section = c.section)
 from class c where pnum in
 (
-  select pnum from professor where deptcode = "PM"
-) and term != 1185
+  select pnum from professor where deptcode = 'PM'
+) and term != 1185;
 
 /*
 The ratio of professors in pure math (PM) to professors in applied math
 (AM) who have taught a class in which the average grade obtained in the
 class was greater than 77.
 */
-select (select count(*) from professor p where deptcode = "PM" and pnum in
+select (select count(*) from professor p where deptcode = 'PM' and pnum in
 (
   (select c.pnum, c.deptcode, c.cnum, c.term, c.section from class c where
   (
@@ -181,13 +183,13 @@ select (select count(*) from professor p where deptcode = "PM" and pnum in
   ) > 77)
 ))
 /
-(select count(*) from professor p where deptcode = "AM" and pnum in
+(select count(*) from professor p where deptcode = 'AM' and pnum in
 (
   select c.pnum, c.deptcode, c.cnum, c.term, c.section from class c where
   (
     select avg(grade) from mark where c.deptcode = deptcode and c.cnum = cnum and c.term = term and c.section = section
   ) > 77
-)) as ratio
+)) as ratio;
 
 /*
 For the current term, report how many courses there are in the schedule
@@ -196,4 +198,4 @@ with a particular number of classes. For example an output
 indicates that there are 5 courses with a single class (section), 4 courses
 with 2 classes, and 1 course with 5 classes scheduled in the curent term.
 */
-select count(*), count(distinct section) from schedule where term = 1185
+select count(*), count(distinct section) from schedule where term = 1185;

+ 1 - 0
a2/test.sql

@@ -0,0 +1 @@
+select count(*), count(distinct section) from schedule where term = 1185;