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