building a query with the database api and groupby multiple fields in drupal 7
Turns out you you can 'stack' the groupby methods like so:

$query-&gt;groupBy('DATE(FROM_UNIXTIME(p.timestamp))')-&gt;groupBy('nid')-&gt;groupBy('hostname');


Which generates the following query string under the hood:

GROUP BY DATE(FROM_UNIXTIME(p.timestamp)), nid, hostname


resulting in the following drupal query for this question:

$query = db_select('pop_links_stats','p');
$query-&gt;fields('p', array('cid','nid','timestamp'));
$query-&gt;groupBy('DATE(FROM_UNIXTIME(p.timestamp))')-&gt;groupBy('nid')-&gt;groupBy('hostname');
$results = $query-&gt;execute()-&gt;fetchAll();