March 25, 2007 at 11:34 pm
Hi,
academic
ID | year | level | m_l
----------------------------------------------
147 | 2006 | dip | 20
course
ID | year | level | course_desc | m_l
----------------------------------------------
147 | 2006 | dip | k | 7
147 | 2006 | dip | b | 11
Hint
----
(1) see course table, select sum(m_l) from course where ID=147 and year=2006 and level='dip' = 18
(2) after query from (1), if user select ID=147, year=2006, level=dip, then m_l receiving 2 or less only (0,1,2).
My problem is 'How to query from academic and course', then result shown as follow:-
ID | year | level | value_left_in_course
----------------------------------------------
147 | 2006 | dip | 2
regards.
March 26, 2007 at 1:23 am
Hi there,
somthing along the lines of the folowing should work:
SELECT a.ID, a.Year, a.Level, a.m_l - c.m_l [value_left_in_course]
FROM
academic a
LEFT JOIN
(SELECT SUM(m_l) [m_l] FROM course GROUP BY ID) b
ON a.ID = b.ID
HTH,
- James
--
James Moore
Red Gate Software Ltd
March 26, 2007 at 8:40 am
This looks like homework. Please do not ask us to solve your homework questions. You should be digging in and writing your own SQL.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply