Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 count in sql

Author  Topic 

niape
Starting Member

4 Posts

Posted - 2011-04-28 : 13:23:44


I'm been trying to figure this out for the last few hours and i'm sure its something easy that i'm missing:

1) Display counts of each grade

2)Display professor lastname of professors

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-28 : 13:39:40
Homework?
I guess this is grading the professor that takes a class.

you only need classes and grades for the first part. I take it you know how to join the tables. Do you know about the group by clause?

For the second part you just need professors and classes.
Get the professorID for professors that teach 1 class - just needs the classes table
Use that result to get the last name from the professor table


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

niape
Starting Member

4 Posts

Posted - 2011-04-28 : 14:52:03
This is keeping track of my personal classes and personal grades

quote:
Originally posted by nigelrivett

Homework?
I guess this is grading the professor that takes a class.

you only need classes and grades for the first part. I take it you know how to join the tables. Do you know about the group by clause?

For the second part you just need professors and classes.
Get the professorID for professors that teach 1 class - just needs the classes table
Use that result to get the last name from the professor table


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-28 : 15:01:06
then - your design is a bit odd - why do you have a grades table?
select g.grade, count(*)
from classes c
join grades g
on g.classid = c.classid
group by g.grade

select lastname
from professors p
where professorid in (select professorid from classes group by professorid having count(*) = 1)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

niape
Starting Member

4 Posts

Posted - 2011-04-28 : 15:09:36
I was required to make three tables

quote:
Originally posted by nigelrivett

then - your design is a bit odd - why do you have a grades table?
select g.grade, count(*)
from classes c
join grades g
on g.classid = c.classid
group by g.grade

select lastname
from professors p
where professorid in (select professorid from classes group by professorid having count(*) = 1)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-28 : 15:24:21
>> This is keeping track of my personal classes and personal grades
>> I was required to make three tables

Sounds even more like homework.
If the requirement was just for 3 tables then it's not a good design. If the requirement gave the design then it's not a good course. Decide whether you want to follow these requirements or keep track of your classes and grades - a sql server database probably isn't a good choice for that.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

niape
Starting Member

4 Posts

Posted - 2011-04-28 : 17:56:01
the requirement was for three tables I did the design. What would you recommend for design improvement?


quote:
Originally posted by nigelrivett

>> This is keeping track of my personal classes and personal grades
>> I was required to make three tables

Sounds even more like homework.
The requirement was for 3 tables, what would be a better design?

If the requirement was just for 3 tables then it's not a good design. If the requirement gave the design then it's not a good course. Decide whether you want to follow these requirements or keep track of your classes and grades - a sql server database probably isn't a good choice for that.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-28 : 19:06:19
Professor
Class
ClassTaken - ProfessorID, ClassID, Grade

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -