Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 10th, 2003, 08:12 AM
LouisRose LouisRose is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 LouisRose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question SQL - Criteria Issue

Hi all,

I'm new to these forums, so I hope this post has gone in the right place. I appologise if it has not.

I have an SQL problem that I was hoping you'd able to help with...

I have two tables, one with a Student's Mark in it and another with Grade Boundaries in them:

Student Marks:
(Student ID | Mark)
(4 | 100)
(5 | 80)
(6 | 79)
(7 | 69)
(8 | 59)


Grade Boundaries:
(Grade | Lower Boundary | Upper Boundary)
(A | 80 | 100)
(B | 70 | 79)
(C | 60 | 69)
(D | 50 | 59)
(U | 0 | 49)


I need an SQL statement which will return (Student ID | Grade).

Now, so far I have this:
SELECT *
FROM [Student Marks], [Grade Boundaries]
WHERE [Lower Boundary])<=[Mark] AND [Upper Boundary]>=[Mark];

This works fine, but I was wondering would I be able to perform the same calculation if I removed the Lower Boundary Field? If so, how would it be performed?

Basically, Grade := Lower <= Mark <= Upper, but Lower and Upper are related, so do I really need to store both??

Any help would be much appreciated.

Thanks for your time.

Regards,
Louis Rose.

Last edited by LouisRose : July 10th, 2003 at 10:18 AM.

Reply With Quote
  #2  
Old July 10th, 2003, 08:59 AM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
You structure allows for a person to have one mark but two different grades. How do you assign the correct grade?
__________________
El éxito consiste en una serie de pequeñas victorias día a día

MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html

Reply With Quote
  #3  
Old July 10th, 2003, 10:17 AM
LouisRose LouisRose is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 LouisRose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ooops that was a typo. I'll edit the original post.

Thanks!

Reply With Quote
  #4  
Old July 10th, 2003, 09:15 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Did you still have a problem? How are you joining the tables?

Reply With Quote
  #5  
Old July 11th, 2003, 06:16 AM
LouisRose LouisRose is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 LouisRose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The problem still exists as stated in my original post. I've just changed a couple of the Grade Boundary numbers.

I'm not joining the tables at all.

Reply With Quote
  #6  
Old July 11th, 2003, 07:16 AM
Jabol Jabol is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Poland
Posts: 57 Jabol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 57 sec
Reputation Power: 5
SELECT * FROM student_marks
CROSS JOIN grade_boundaries
HAVING student_marks.id BETWEEN grade_boundries.lower AND grade_boundries.upper

Don't know if it'll work, but I think the idea is good.

Reply With Quote
  #7  
Old July 11th, 2003, 07:28 AM
LouisRose LouisRose is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 LouisRose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Jabol, I've not tried you suggestion yet but it looks good.

The nub of the problem is removing a field (either lower boundary or upper boundary) though, as:

Upper Boundary(x) = Lower Bounary(x-1) + 1

where x is the Grade.

Reply With Quote
  #8  
Old July 11th, 2003, 10:17 AM
MattR MattR is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: High above the mucky-muck (Columbus, OH)
Posts: 266 MattR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to MattR
Well, if you don't store both bounds, then you must join the grade_boundary table TWICE in order to get the boundary. If my mark is 76 with only a high-boundary I can tell what grades it is NOT (B or A), but I don't know if it is a C or not until I look at where the C mark cutoff is.

You could accomplish this 'one boundary' method with some bastardization of SQL -- you could do an ORDER BY boundary (acending or decending depends on where you put your boundaries) and take the first row that pops up.

What you have now is fine, why do you want to change it?

Reply With Quote
  #9  
Old July 11th, 2003, 12:56 PM
LouisRose LouisRose is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 LouisRose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I want to change it as the end user does not want to have to change both A's lower boundary and B's upper boundary when the grade boundary works.

Could you give me an example in SQL to try please? Thanks.

Regards,
Louis.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL - Criteria Issue


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway