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 > Lowest Marks

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-03, 12:46
johnwayneaussie johnwayneaussie is offline
Registered User
 
Join Date: Jul 2003
Posts: 2
Question Lowest Marks

I have the following 3 tables.
Student Table : S_ID, FNAME, LNAME
UNIT : U_ID, UNITNAME
Marks Table : S_ID, U_ID, YEAR, MARKS
A student can enrol in multiple units of study each year. At enrolment by default their marks is zero.

Given a certain year we need to output the lowest marks obtained by a student in each unit. Students with zero marks should be excluded.
The SQL query shall output the following :
FNAME, LNAME, UNITNAME, MARKS
Example find the lowest marks obtained for all units in 2002. (The unitname can only appear once in the result).

Can the above query be performed in a single select statement? If yes how ? If no what is the alternate?
Reply With Quote
  #2 (permalink)  
Old 07-11-03, 14:07
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Thumbs down Lowest Marks

Hi
Kindly use the following query to get the required results.

select t1.sid, t1.fname, t1.u_id, l2.u_name, t1.marks from (select l1.sid, l1.fname, l3.u_id, l3.marks from L1, L3 where L1.sid=l3.sid and l3.marks!=0) t1, l2 where t1.u_id=l2.u_id;

Thanx and Regards
Aruneesh
Reply With Quote
  #3 (permalink)  
Old 07-11-03, 14:07
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Talking All in one query

Everything that you wanted is coming packaged in just one query.
Hope it works for you fine.
Reply With Quote
  #4 (permalink)  
Old 07-11-03, 22:54
johnwayneaussie johnwayneaussie is offline
Registered User
 
Join Date: Jul 2003
Posts: 2
Question Re: All in one query rephrased

I suppose the question was not clear therefore the reply by aruneeshsalhotr did not answer the qestion. I will try & simplify with an example.

Student Table : S_ID, FNAME, LNAME
Student Data :
001, Jack, Russel
002, Mark, Benny
003, John, Wayne

Unit Table : U_ID, UNITNAME
Unit Data :
MA, Maths
EN, English
SC, Science

Marks Table : S_ID, U_ID, YEAR, MARKS
Marks Data :
001, MA, 2002, 80
001, EN, 2002, 60
001, SC, 2002, 0
002, MA, 2002, 50
002, EN, 2002, 70
002, SC, 2002, 60
003, MA, 2002, 0
003, EN, 2002, 0
003, SC, 2002, 55
003, MA, 2003, 50
003, EN, 2003, 70
001, SC, 2003, 50

The Output required for the query -> find the lowest marks obtained for all units in 2002 is as follows:
FNAME, LNAME, UNITNAME, MARKS
Jack, Russel, English, 60
Mark, Benny, Maths, 50
John, Wayne, Science, 55
In the above result all those with 0 marks have been eliminated.

Is it possible to have a all in one query for the above output?
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