SQL PHP HTML ASP JavaScript articles and free scripts to download

Group by query in MSSQL Table

In our student database we have seen how count query works. Now we will discuss how to display total number of records based on GROUP By SQL command. You can read more on GROUP BY command here.


Let us try to display total number of students in each class. Here we will display class name and number of students in the class.

You can read the basic SELECT QUERY here , we will only change the sql part here.

rs1.open " select COUNT(class) as no,class from student group by class " , conn

Within the Do While loop we will keep this code to display the data.

Response.Write rs1("class") & rs1("no") & "<br>"

GROUP BY command with SUM

We can find out total mark of students in each class by using SUM and GROUP BY sql commands. Here is the query and display part

rs1.open " select SUM(mark) as no,class FROM student GROUP BY class " , conn

GROUP BY command with AVG

Same way we can get teh average mark in each class by using AVG command with GROUP BY

rs1.open " select AVG(mark) as no,class FROM student GROUP BY class " , conn

GROUP BY command with MAX and MIN

Same way we can find out the highest mark in each class by using MAX command and the minimun mark by using MIN query

rs1.open " select MAX(mark) as no,class FROM student GROUP BY class " , conn
rs1.open " select MIN(mark) as no,class FROM student GROUP BY class " , conn

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer