Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    19

    Answered: Invalid use of group function?

    Hi all,
    Getting stumped on this invalid use of group function error. I am not using a group by clause so I am somewhat confused:

    Code:
    SELECT
    SUM(CASE WHEN NOT hours.jobnum='0'  THEN ROUND(SUM(TIME_TO_SEC(TIMEDIFF(hours.clockout, hours.clockin))/3600)) ELSE 0 END) as cadon,
    SUM(CASE WHEN hours.jobnum='0'  THEN ROUND(SUM(TIME_TO_SEC(TIMEDIFF(hours.clockout, hours.clockin))/3600)) ELSE 0 END) as cadoff
    FROM hours, employees WHERE hours.empid = employees.employeeid AND YEAR(hours.clockout)='2015' AND employees.class='working' AND employees.firstname='Someone'
    Any help appreciated. I have many case queries in mssql but never mysql so perhaps there is an error somewhere that I can't spot.
    Thanks!

  2. Best Answer
    Posted by MCrowley

    "I would bet MySQL is complaining about the nested SUM functions, but that is mostly a guess. Can you try it without the inner SUM?"


  3. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    I would bet MySQL is complaining about the nested SUM functions, but that is mostly a guess. Can you try it without the inner SUM?

  4. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    if you are using an aggregate function, SUM, COUNT, MIN, MAX, etc... you must use a group by. Unless that is the only column you are selecting
    Dave

  5. #4
    Join Date
    Dec 2010
    Posts
    19
    Quote Originally Posted by MCrowley View Post
    I would bet MySQL is complaining about the nested SUM functions, but that is mostly a guess. Can you try it without the inner SUM?
    You got it! I didn't even notice that as I built this query from an old one that already had a sum. Removed it and no errors.
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •