Jump to content

Multiple Group Bys?


Garethp

Recommended Posts

Hey guys, I'm having a little problem. I have three tables. sites, devices, and device_status. Basically, device_status holds multiple rows per device, of when the device last pinged on of our servers, and each site can have multiple sites.

 

So what I'm trying to do is find when a site was first created, but finding when it's devices first pinged us, and get all sites set up since October. What I tried was

 

SELECT sites.*, MIN(device_status) as firstcontact FROM sites

LEFT JOIN devices ON devices.siteid=sites.id

LEFT JOIN device_status on device_status.deviceid=devices.id

GROUP BY sites.id

HAVING

firstcontact > UNIX_TIMESTAMP('2010-08-01')

ORDER BY firstcontact DESC

 

But it shows no sites, and only two sites when I change it to January of 2010. My guess is that this is a result of the GROUP BY sites.id, and I was thinking that if I could somehow group by devices and sites it might show the correct results. How would I do this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.