Jump to content

Grouping by days


DarkReaper

Recommended Posts

Hello i have a table with structure:
[code]
  `id` int(10) NOT NULL auto_increment,
  `site_id` int(10) NOT NULL default '0',
  `time` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `site_id` (`site_id`)

[/code]

My problem is that i want to select all entries by days. My date cell is time, and its unixtime stamp. I know how to select the entries from today ... but i want to group them by all the days available.

[code]SELECT count(id) as total FROM uniques WHERE site_id=2 GROUP BY TO_DAYS(FROM_UNIXTIME(TIME));[/code]

This code returns all the entries from today. Because of the "TIME" code. I've tried also:

[code]SELECT count(id) as total FROM uniques WHERE site_id=2 GROUP BY TO_DAYS(FROM_UNIXTIME(uniques.time));[/code]

But the result was the same. Helppp :)

Short version: I have the table from above, i want to select all entries grouped by days. My time stamp is the unix default and its stored in the cell -> time.


--------------------


WHOOPS! My bad. I've forgotten to cycle though the returned rows ... sorry the
[code]SELECT count(id) as total FROM uniques WHERE site_id=2 GROUP BY TO_DAYS(FROM_UNIXTIME(uniques.time));[/code]
Does the trick. Case closed :)
Link to comment
https://forums.phpfreaks.com/topic/21643-grouping-by-days/
Share on other sites

My last problem is that i have 3 tables, and i need the data from them to be merged by this sql query.

The tables are as follows uniques, impr, vis. I need to extract the same data at the same time from them, with 1 query. I know how to do it with multiple queries but i dont like that way, its too uniefficient.
Link to comment
https://forums.phpfreaks.com/topic/21643-grouping-by-days/#findComment-96590
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.