views:

40

answers:

1

Hi,

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,

+2  A: 

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.

Mark Byers
Hi, I tried what you said but it does not work. i guess problem is that dtime is different.My records are like this for eg:id dtime ifInOctet1 9:20 1002 9:20 903 9:20 781 9: 21 232 9:21 501 9:22 33 9:22 200I want to group all 1 together but do not want to add up the values of IfInOctet. Any idea?
jillika iyer