Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

In my application i am inserting below values in database and displaying in grid.

name
subject
marks

now i have another grid where i have to display below information

name
average

average will be calculated as total_marks/300

total_marks is sum of all subject marks.


Please tell me how to display this..
Posted
Comments
Please show your progress and indicate the problem.
Snehasish999 7-Jan-14 13:01pm    
so far did like this


SqlCommand cmd1 = new SqlCommand("Select name from student", con);
con.Open();
String value = cmd1.ExecuteScalar() as String;
if (TextBox1.Text.Equals(value))
{
SqlCommand str = new SqlCommand("")
}
now i want to do like sum of marks column/ 300 and display in grid.
Snehasish999 7-Jan-14 13:23pm    
i have this query

select AVG(marks) from student
where name='snehasish'

It's giving me the average but i want the student name also.
if i include name it's giving error
Use like...

SELECT name, AVG(marks) FROM student
WHERE name='snehasish'
GROUP BY name
Snehasish999 7-Jan-14 13:48pm    
name i am taking from textbox..how to pass the textbox value to the sqldatasource query

1 solution

Try:
SQL
SELECT [name], SUM(marks)/300 AS Average
FROM student
GROUP BY [name]


[edit]AVG changed to SUM to match OP - OriginalGriff[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900