GROUP BY creation date

This is a discussion on GROUP BY creation date within the MySQL Database forums, part of the Database Forums category; I have a table structure which includes a UNIX timestamp (seconds since '1970-01-01 00:00:00' UTC) for ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-25-2006
Bosconian
 
Posts: n/a
Default GROUP BY creation date

I have a table structure which includes a UNIX timestamp (seconds since
'1970-01-01 00:00:00' UTC) for the creation date.

I would like to return a record count grouped by creation date using the
time range from 00:00:00 to 23:59:59 for each respective day.

For example:

Date, Count

24 October, 23
23 October, 12
22 October, 16

Can this one done in one query using only SQL?


Reply With Quote
  #2 (permalink)  
Old 10-25-2006
strawberry
 
Posts: n/a
Default Re: GROUP BY creation date


Bosconian wrote:
> I have a table structure which includes a UNIX timestamp (seconds since
> '1970-01-01 00:00:00' UTC) for the creation date.
>
> I would like to return a record count grouped by creation date using the
> time range from 00:00:00 to 23:59:59 for each respective day.
>
> For example:
>
> Date, Count
>
> 24 October, 23
> 23 October, 12
> 22 October, 16
>
> Can this one done in one query using only SQL?


Untested, and just a guess:

SELECT DATE( FROM_UNIXTIME( field ) ) AS creation_date,
COUNT(DATE(FROM_UNIXTIME(field)) AS cnt
FROM table
GROUP BY creation_date

Reply With Quote
  #3 (permalink)  
Old 10-25-2006
Bosconian
 
Posts: n/a
Default Re: GROUP BY creation date

"strawberry" <zac.carey@gmail.com> wrote in message
news:1161781148.385250.97210@i3g2000cwc.googlegrou ps.com...
>
> Bosconian wrote:
>> I have a table structure which includes a UNIX timestamp (seconds since
>> '1970-01-01 00:00:00' UTC) for the creation date.
>>
>> I would like to return a record count grouped by creation date using the
>> time range from 00:00:00 to 23:59:59 for each respective day.
>>
>> For example:
>>
>> Date, Count
>>
>> 24 October, 23
>> 23 October, 12
>> 22 October, 16
>>
>> Can this one done in one query using only SQL?

>
> Untested, and just a guess:
>
> SELECT DATE( FROM_UNIXTIME( field ) ) AS creation_date,
> COUNT(DATE(FROM_UNIXTIME(field)) AS cnt
> FROM table
> GROUP BY creation_date
>


Cool, this looks like it works. I just needed to add a third parenthesis
after the COUNT clause. Thanks!


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:31 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0