我们如何在SQL中获得最高分查询,请参见下文: [英] How can we get Highest marks query in SQL, See Below :

查看:73
本文介绍了我们如何在SQL中获得最高分查询,请参见下文:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi All, I have a database with multiple records. See Table Structure Below :

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.



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. 

推荐答案

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


祝您编码愉快!
:)


Happy Coding!
:)


SELECT 
  Subject
, Sub_category
, SUM(Marks) AS Marks
, User_Type
FROM YourTable
GROUP BY
  Subject
, Sub_category
, User_Type


这就是为什么我们有GROUP BY子句的原因 [ ^ ].
This is why we have GROUP BY clauses[^].


这篇关于我们如何在SQL中获得最高分查询,请参见下文:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆