SQL ACCESS- Tried to execute a query that..

Custom / CUSTOM
October 13, 2010 at 01:51:31
Specs: Windows 7, 8g
How do I finish this code. I have tried multiple attempts but this is the closest I have gotten. I am trying to print the ID, Year and Semester from one table and count the number of units per semester from the other table. Here is my code. Feel free to ask any questions and thanks very much for any help you can provide.


SELECT T.TPId, T.Year, T.Semester, COUNT (U.UOId)
FROM TeachingPeriod T, UnitOffered U
GROUP BY U.TP


See More: SQL ACCESS- Tried to execute a query that..

Report •

#1
March 4, 2011 at 19:00:09
hi
Your "group by" section has the problem. you must write all the fields of the "select" section. Your code becomes:
SELECT T.TPId, T.Year, T.Semester, COUNT (U.UOId)
FROM TeachingPeriod T, UnitOffered U
GROUP BY T.TPId, T.Year, T.Semester

That's if you want to group according to : ID, Semester and also Year
if you want to get the number of units according to the semester you can try the following :
SELECT T.TPId, T.Year,T.Semester,(SELECT count(U.UOID) from UnitOffered U
group by U.Semester
where U.Semester= T.Semester)
from TeachingPeriod T

Report •
Related Solutions


Ask Question