简体   繁体   English

如何根据另一列的唯一ID获取一列的最大值,平均值,最小值,计数

[英]How to get max value, average, min, count from one column based on a unique id from another column

    SELECT  [Student ID]
      ,[Course ID]
      ,[Name]
      ,max[Marks]
      ,[Grade]
  FROM [CE].[dbo].[GradeCount]
  order by [Student ID]    

use aggregation and group by 使用汇总和分组

 SELECT [Student ID]
      ,[Course ID]
      ,[Name]
      ,max([Marks])
      ,max([Grade])
  FROM [CE].[dbo].[GradeCount]
 group by [Student ID] ,[Course ID],[Name]

Just use GROUP BY fields you want to use aggregation functions such as MAX , MIN , AVG , COUNT : 只需使用您要使用聚合函数(例如MAXMINAVGCOUNT GROUP BY字段即可:

  SELECT 
    MAX(course_ID) MaxCourse_ID
  , MIN(course_ID) MinCourse_ID
  , AVG(course_ID) AvgCourse_ID
  , COUNT(course_ID) CountCourse_ID
  FROM [CE].[dbo].[GradeCount]
  group by course_ID

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL根据来自另一个相关表中的列的相应最小值/最大值(值)获取值 - SQL get value based on corresponding min/max(value) from column in another related table 如何根据另一列的最大值从一列中选择一个值,如果相同,则使用另一列的最大值 - How to select a value from one column based on the max value of another column and if that's the same, use the max value of another column 从与另一列中的特定ID相关联的一列中找到最小值和最大值 - Find the min and max values from one column associated with a particular id from another column 如何根据 postgresql 中另一列的最小值和最大值拆分列 - How to split column based on the min and max value of another column in postgresql 从另一列的 MIN() 和 MAX() 值创建计算字段,按唯一 ID 分组 - Create calculated field from MIN() and MAX() values of another column, grouped by unique ID 基于一列的最大值和另一列的特定ID的SQL选择 - SQL Select Based On Max Value of One Column and Specific Id from Another 根据另一列的最大值从一列检索值 - Retrieving value from one column based off max of another 如何根据另一列中的值从一列中选择唯一值? - How to select unique values from one column based on a value in another column? 如何基于最大和最小序列的另一个表值更新列 - How to update a column based on another table value for max and min sequence SQL:获取一列中的最小值和最大值 - SQL : get Min and Max value in one column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM