Home > database >  Filter and sum query in visual studio 2022
Filter and sum query in visual studio 2022

Time:12-17

I have a project with visual studio 2022 using Microsoft access database. I have a table shown as below:

Student Info

Name  Student_Class Individual_Marks
Jane        5A            70
Jade        5B            60
Jean        5A            30
Jade        4B            20

How can I create a sql query in visual studio where it will show the class total marks in a existing table like below?

Class Sum Marks

Class Total_Marks
5A        100
5B        60
4B        20

This is the query I tried in access which will filter and sum, and create a new table itself. But it is not practically when I have a window form in visual studio since this need to click run in MS access side to get the result and I just can't figure out how to bring that into visual studio there.

SELECT [Student Info].Student_Class, [Student Info].Individual_Marks INTO [Class Sum Marks]
FROM [Student Info];

CodePudding user response:

You need an aggregating query like:

SELECT 
    Student_Class As Class, 
    Sum([Individual_Marks]) As [Total_Marks]
FROM 
    [Student Info]
GROUP BY
    Student_Class
  • Related