0

I have used the following query:

select tblclass.classname,tblattendance.id 
 from tblclass,tblattendance
where tblclass.classcode=tblattendance.classcode 
  and tblattendance.attdate='2013-07-01'

Output of this query is as follows:

enter image description here

Now what I want is rather than the above result I want count of different classes like IB-2,IC-5. Please tell me what modifications do I need to made in my query to get the desired result

1
  • thank you all.All the 3 answers worked for me:) Commented Sep 24, 2013 at 7:53

3 Answers 3

3

Use the Group By SQL clause and add the aggregate function Count

select tblclass.classname, Count(tblattendance.id) as counter 
from tblclass,tblattendance 
where tblclass.classcode=tblattendance.classcode and tblattendance.attdate='2013-07-01'
group by tblclass.classname
Sign up to request clarification or add additional context in comments.

2 Comments

i have a table tblstudent now i want a field where i can get no of students present in tblattendance on given date and total no of students in that class
Please open a new question
0

Try this

select count(tblattendance.id),tblclass.classname from tblclass,tblattendance 
where tblclass.classcode=tblattendance.classcode and tblattendance.attdate='2013-07-01' 
group by tblclass.classname

Comments

0

Use COUNT() function for that with GROUP BY. Also use JOIN.

SELECT tc.classname, COUNT(tc.classname) AS COUNTS
  FROM tblclass tc 
  JOIN tblattendance tt
    ON tc.classcode = tt.classcode
 WHERE tt.attdate='2013-07-01'
 GROUP BY tc.classname

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.