GROUP BY using parameters in SQL

前端 未结 4 1999
一整个雨季
一整个雨季 2020-12-19 11:01

I am trying to somehow group a report based on a drop-down list of parameters that is pre-defined. I want to be able to subtotal the Total Hours or Total Pay of my report b

4条回答
  •  长情又很酷
    2020-12-19 11:50

    Any column you are selecting that are not used by one of the aggregate function (SUM, MIN, etc) needs to be listed in the GROUP BY clause.

    For example,

    SELECT EmployeeID, LastName, FirstName, SUM(Hours) as "Total Hours"
    FROM Employees
    GROUP BY EmployeeID, LastName, FirstName
    

    Good examples here: http://www.w3schools.com/sql/sql_groupby.asp

提交回复
热议问题