简体   繁体   中英

Calculating average of students' scores (with different coefficients)

I have to calculate the average of students scores.

Students have two different scores: midterm, and final.

first course average = ( (midterm score*1) + (Final score*2) ) / 3 )

How can do this by ASP.NET (C#) and SQL?

This confuses me. Which part should be written with C# or SQL?

Depends on what flavor of SQL You can do this all in SQL by simply creating a new column 'first course average'. Assuming you have a table with one record per student

SELECT ([Midterm Score] + (2 * [Final Score])) / 3 AS 'first course average'
FROM #gradeTable 
GROUP BY [Student ID]

You could alternatively use the LINQ library in C#, but given the simplicity of this exercise, that really isn't necessary.

The scores will all be stored in a sql database. you can also do the calculations in Sql using specialized queries. In this case it may be easiest to just retrieve the scores and do the calculations in c# (or any other programming language) I like python and php, but everything ahs it's place.

Does that answer your question.

You can direct calculate from SQL like this:

SELECT ((Midterm + (Final*2))/3) AS First_Course_Average FROM Scores WHERE ...

See this SQLFiddle

You can do that also by writing it in the formula section. which can be found in column properties .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM