mysql - SQL Multiple GROUP BY -
i can't figure out mysql query extract info want table "timeentry":
hours creationdate userid clientid projectid taskid 20 2012-02-18 1 1 1 1 40 2012-02-18 1 1 1 1 30 2012-02-21 2 1 1 1 20 2012-02-22 2 1 1 2 30 2012-02-22 2 1 1 2 80 2012-02-23 1 2 2 2 10 2012-02-23 3 2 2 2 15 2012-02-23 1 2 2 3 40 2012-02-23 1 2 4 1
and have kind of result table, or csv/excel file or php array (where totalhours sum of hours userid) given period of time, allow (between 2012-02-01 , 2012-02-25):
clientid projectid taskid userid totalhours 1 1 1 1 60 2 30 2 2 50 2 2 2 1 80 3 10 3 1 15 4 1 1 40
i guess have utilize multiple grouping by, tried like:
select clientid, projectid, taskid, userid, sum(hours) `timeentry` date_creation >= "2012-02-01" , date_creation <= "2012-02-25" grouping clientid, projectid, taskid, userid;
but didn't work...
thanks in advance.
where needs go before grouping by.
if want filter date before grouping, utilize clause have moved before grouping by.
if you'd instead filter entire groups in or out, utilize having:
... grouping ... having max(date) <= somevalue , min(date) >= somevalue
mysql sql
No comments:
Post a Comment