JJunior
JJunior

Reputation: 2849

Group by - multiple conditions - MySQL

How can I combine 2 group by conditions? I have records for each id for every hour in a day and I want to group information by first id and all records for that id in that day then second id and all records for that in the day.

My sample query is this:

SELECT
    r.name
  , r.network
  , r.namestring
  , i.name
, i.description
  , r.rid
  , i.id
  , d.dtime
  , d.ifInOctets
FROM router AS r
INNER JOIN interface AS i
ON r.rid = i.rid
INNER JOIN 1279080000_1_60 AS d
ON i.id = d.id
AND dtime BETWEEN 1279113600 AND 1279115400
WHERE r.network = "ITPN"
AND i.status = "active"
GROUP BY i.id AND d.dtime              // each id with all its dtime

This always ends up giving me an aggregate value for that id. Any idea what I could use??? I don't want to sum up all values.

Thank you,

Upvotes: 4

Views: 22709

Answers (1)

Mark Byers
Mark Byers

Reputation: 837996

To group by multiple expressions you should separate them with a comma, not AND:

GROUP BY i.id, d.dtime

You should also ensure that two records form the same day have the same value of dtime. It's not clear from your question whether this is or is not the case.

Upvotes: 10

Related Questions