If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-30-07, 17:51
piston piston is offline
Registered User
 
Join Date: Oct 2007
Posts: 13
SQL Query

Hi, I am studying SQL at the mom and can deal with most simple query. I am having problems with more complex ones like joining tables etc. A prime example is the following

3 tables

CREATE TABLE Student
(RegNo NUMBER
CONSTRAINT PK_Student PRIMARY KEY,
Name VARCHAR2(20)
CONSTRAINT NOT_NULL_Student_Name NOT NULL) ;

CREATE TABLE Unit
(UnitCode CHAR(4)
CONSTRAINT PK_Unit PRIMARY KEY,
Name VARCHAR2(20)
CONSTRAINT NOT_NULL_Unit_Name NOT NULL) ;

CREATE TABLE Result
(UnitCode CHAR(4)
CONSTRAINT FK_Result_Unit REFERENCES Unit,
Regno NUMBER
CONSTRAINT FK_Result_Regno REFERENCES Student,
AcadYear NUMBER
CONSTRAINT NOT_NULL_Acad_Year NOT NULL,
Percent NUMBER,
CONSTRAINT PK_Result PRIMARY KEY
(UnitCode,Regno,AcadYear)) ;

Query = Show the average marks for each student, listing the students by their Names

My attempt=

SELECT name, AVG(Percent)
FROM Student s, Result r
WHERE s.Regno = r.Regno
ORDER BY s.name

I know this is wrong but could someone tell me Y

Thanks.
Reply With Quote
  #2 (permalink)  
Old 10-30-07, 23:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
check your manual for the difference between ORDER BY and GROUP BY
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On