Home » Other » Training & Certification » SQL Help
SQL Help [message #278416] |
Sun, 04 November 2007 00:28 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
orangejuice
Messages: 3 Registered: November 2007
|
Junior Member |
|
|
Hello everyone, i've been trying to figure this out for a while but to no avail and am running out of time so plz any help is appreciated.
My tables are: School, Area, Student, Majors, Minors
Heres my task:
1)
Select the id and name of all students who are minoring in any area belonging to the 'Basket Weaving and Juggling' school; Make sure each student appears only once, even if minoring in more than one area within that school.
2)
The name of each area with the number of students who are minoring on it, plus the age of the oldest student(s) majoring on it, and the average age of all students majoring on it. Make sure ALL areas appear, even those with no students majoring on it.
For Task 1, this is what i've been able to come up with
select Distinct S.name, S.id
from Student S JOIN Minor M ON (S.id = M.student) Join Area A ON (A.id = M.Area) JOIN School H ON (A.school = H.id)
where H.name = 'Basket Weaving and Juggling';
but i get the no row selected response, which is odd b/c i was expecting it to return some columns......here are the data in the tables
INSERT INTO School (Id, Name) VALUES (1, 'Computing and Software Engineering');
INSERT INTO School (Id, Name) VALUES (2, 'Basket Weaving and Juggling');
INSERT INTO Area (Id,Name,School) VALUES
(1,'Computer Science',1);
INSERT INTO Area (Id,Name,School) VALUES
(2,'Software Engineering',1);
INSERT INTO Area (Id,Name,School) VALUES
(3,'Information Technology',1);
INSERT INTO Area (Id,Name,School) VALUES
(4,'Basket Weaving',2);
INSERT INTO Area (Id,Name,School) VALUES
(5,'Juggling',2);
INSERT INTO Minors (Student,Area) VALUES (1,5);
INSERT INTO Minors (Student,Area) VALUES (2,1);
INSERT INTO Minors (Student,Area) VALUES (2,4);
INSERT INTO Minors (Student,Area) VALUES (3,5);
INSERT INTO Minors (Student,Area) VALUES (4,5);
For task 2:
I don't know where to start with this one
Thnx to any1 who helps
[Updated on: Sun, 04 November 2007 01:08] Report message to a moderator
|
|
|
|
Re: SQL Help [message #278421 is a reply to message #278416] |
Sun, 04 November 2007 01:56 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
orangejuice
Messages: 3 Registered: November 2007
|
Junior Member |
|
|
Oracle 10i
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(1, 'Light Yamagashi',30, 'M');
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(2, 'Lina Colli',29, 'F');
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(3, 'John Smith',18, 'M');
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(4, 'Jane Smith',19, 'F');
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(5, 'Ruben Rada',20, 'M');
INSERT INTO Student(Id, Name, Age, Gender) VALUES
(6, 'Manuel Morales',21, 'M');
INSERT INTO Majors (Student,Area) VALUES (1,4);
INSERT INTO Majors (Student,Area) VALUES (2,1);
INSERT INTO Majors (Student,Area) VALUES (3,2);
INSERT INTO Majors (Student,Area) VALUES (4,3);
INSERT INTO Majors (Student,Area) VALUES (4,4);
CREATE TABLE School (
Id INTEGER PRIMARY KEY,
Name VARCHAR(45) UNIQUE NOT NULL
);
CREATE TABLE Area (
Id INTEGER PRIMARY KEY,
Name VARCHAR(25) UNIQUE NOT NULL,
School INTEGER NOT NULL
REFERENCES School(id)
);
CREATE TABLE Student (
Id INTEGER PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Age INTEGER NOT NULL,
Gender CHAR(1) NOT NULL
CHECK(Gender IN ('M','F'))
);
CREATE TABLE Majors (
Student INTEGER REFERENCES Student(Id),
Area INTEGER REFERENCES Area(Id),
PRIMARY KEY(Student,Area)
);
CREATE TABLE Minors (
Student INTEGER REFERENCES Student(Id),
Area INTEGER REFERENCES Area(Id),
PRIMARY KEY(Student,Area)
);
[Updated on: Sun, 04 November 2007 01:57] Report message to a moderator
|
|
|
|
|
|
Re: SQL Help [message #279137 is a reply to message #279080] |
Wed, 07 November 2007 01:55 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](/forum/images/custom_avatars/102589.gif) |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Instead of deleting the topic, it would better you post the queries you find in order to help others in their problem and maybe we can enhance them for the good of everyone.
Regards
Michel
|
|
|
Goto Forum:
Current Time: Tue Feb 11 20:15:00 CST 2025
|