What does group by do exactly ?

前端 未结 1 1663
悲&欢浪女
悲&欢浪女 2021-01-03 05:47

From an example taken from here , I\'m trying to understand what does GROUP BY do exactly :

Given this employee table :

+-         


        
相关标签:
1条回答
  • 2021-01-03 06:39

    GROUP BY enables summaries. Specifically, it controls the use of summary functions like COUNT(), SUM(), AVG(), MIN(), MAX() etc. There isn't much to summarize in your example.

    But, suppose you had a Deptname column. Then you could issue this query and get the average salary by Deptname.

    SELECT AVG(Salary) Average,
           Deptname
      FROM Employee
     GROUP BY Deptname
     ORDER BY Deptname
    

    If you want your result set put in a certain order, use ORDER BY.

    0 讨论(0)
提交回复
热议问题