ItHurtsWhenIThink
Technical User
First, I thought that table I created was just going to track birthdays and then my small simple task grew. At first we just wanted to remind teachers of their student birthdays, then we added other data. I would have created a totally different schema had I known. But, here I am.
We decided to give our academy students polo shirts. So I just added shirt size and gender to the table.
Problem was that there are duplicate students with same student ID. A student may have many teachers within the academy. I know... at the beginning all we were going to is iterate through the table and send reminders of birthdays only the teachers that have the specific student.
Now I need to query and get a count of the sizes based on gender and size.
So I want:
F XS 3
F S 10
F M 18
F L 9
M S 1
M M 10
M L 20
Where 1st column= gender, 2nd = size and third = qty
Here is my query. Problem is I just can't figure out how to only get distinct count based on studentID, since there are many if the same ID.
here is what I am using (it gives my wrong count because it counts same student several times)
Select Count(ShirtSize) AS ctSizes, ShirtSize, Gender
from academybirthdays
Where ShirtSize IN('XS','S','M','L','XL','XXL','XXXL') /// there are some null vales
AND
StudentID in (select Distinct(StudentID) from StudentIDs)
Group By Gender,ShirtSize
The studentids table allow me to filter out those students that are not in the academy or qualify for a shirt.
Anyone have a solution for me? thanks....
We decided to give our academy students polo shirts. So I just added shirt size and gender to the table.
Problem was that there are duplicate students with same student ID. A student may have many teachers within the academy. I know... at the beginning all we were going to is iterate through the table and send reminders of birthdays only the teachers that have the specific student.
Now I need to query and get a count of the sizes based on gender and size.
So I want:
F XS 3
F S 10
F M 18
F L 9
M S 1
M M 10
M L 20
Where 1st column= gender, 2nd = size and third = qty
Here is my query. Problem is I just can't figure out how to only get distinct count based on studentID, since there are many if the same ID.
here is what I am using (it gives my wrong count because it counts same student several times)
Select Count(ShirtSize) AS ctSizes, ShirtSize, Gender
from academybirthdays
Where ShirtSize IN('XS','S','M','L','XL','XXL','XXXL') /// there are some null vales
AND
StudentID in (select Distinct(StudentID) from StudentIDs)
Group By Gender,ShirtSize
The studentids table allow me to filter out those students that are not in the academy or qualify for a shirt.
Anyone have a solution for me? thanks....