Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All, I have a database with multiple records. See Table Structure Below :

id        Subject       Sub_category       Marks      User_Type

1         Science        Physics             4          tom
2         Science        Physics             2          tom                           
3         Science        Physics             1          tom                             
4         Science        Chemistry           4          tom                                  
5         Science        Chemistry           5          tom                               
6         Science        Biology             5          tom                            
7         Science        Biology             3          tom                         
8         Math           Alebra              2          tom
9         Math           Alebra              3          tom                          
10        Math           Statics             5          tom
11        Math           Statics             3          tom      
10        English        Grammer             5          tom
11        English        Grammer             1          tom      
10        English        Grammer             3          tom      
11        English        Theory              1          tom  
11        English        Theory              5          tom 


Now I needs a query which shows addition marks of particular Sub_category, with count.. See below.

Subject       Sub_category       Marks      User_Type


Science        Physics             7          tom

Science        Chemistry           9          tom

Science        Biology             8          tom

Math           Alebra              5         tom

Math           Statics             8          tom

English        Grammer             9          tom

English        Theory              6          tom

<br />
Can any one have an idea, kindly share with me. 
Posted

SQL
select subject,sub_category,sum(marks) as marks,user_type 
from yourTbl
group by  subject,sub_category,user_type

Happy Coding!
:)
 
Share this answer
 
Comments
Mas11 20-Sep-12 1:36am    
Wonderfull aarti, u glad me a lot.. Thanks for ur answer.
Aarti Meswania 20-Sep-12 1:37am    
welcome,
Glad to help you! :)
SQL
SELECT 
  Subject
, Sub_category
, SUM(Marks) AS Marks
, User_Type
FROM YourTable
GROUP BY
  Subject
, Sub_category
, User_Type
 
Share this answer
 
Comments
Mas11 20-Sep-12 1:37am    
Thanks a lot !!.
Kuthuparakkal 20-Sep-12 2:13am    
welcome buddy
This is why we have GROUP BY clauses[^].
 
Share this answer
 

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