Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
last item of each day
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
NickPick  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 20:48
Newsgroups: comp.databases.mysql
From: NickPick <dickreu...@yahoo.com>
Date: Tue, 3 Nov 2009 12:48:30 -0800 (PST)
Local: Tues 3 Nov 2009 20:48
Subject: last item of each day
I have a list with entries and each entry has a timestamp. I'd like to
show that last entry of each day only, for the last 30 days. How can I
do this?

Any help is appreciated


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 22:06
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Tue, 3 Nov 2009 14:06:02 -0800 (PST)
Local: Tues 3 Nov 2009 22:06
Subject: Re: last item of each day
On Nov 3, 3:48 pm, NickPick <dickreu...@yahoo.com> wrote:

> I have a list with entries and each entry has a timestamp. I'd like to
> show that last entry of each day only, for the last 30 days. How can I
> do this?

SELECT *
FROM t JOIN (
    SELECT MAX(ts) AS max_ts -- `ts` is the timestamp column
    FROM t
    GROUP BY DATE(ts)
    WHERE DATEDIFF(NOW(), ts) <= 30
) Day ON t.ts = Day.max_ts

This will give you multiple entries where timestamps are equal, so you
may want to use the auto-incrementing id instead (if you have one),
i.e. MAX(id) in the same group.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NickPick  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 23:43
Newsgroups: comp.databases.mysql
From: NickPick <dickreu...@yahoo.com>
Date: Tue, 3 Nov 2009 15:43:30 -0800 (PST)
Local: Tues 3 Nov 2009 23:43
Subject: Re: last item of each day
On Nov 3, 10:06 pm, toby <t...@telegraphics.com.au> wrote:

I get this error message:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'WHERE DATEDIFF(NOW(), timestamp) <= 30 ) Day ON trades.timestamp
= Day.max_ts ' at line 6

this is what I used (table name: trades, timestamp column is called
timestamp)

SELECT *
FROM trades JOIN (
    SELECT MAX(timestamp) AS max_ts
    FROM trades
    GROUP BY DATE(timestamp)
    WHERE DATEDIFF(NOW(), timestamp) <= 30
) Day ON trades.timestamp = Day.max_ts


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 03:05
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Tue, 3 Nov 2009 19:05:31 -0800 (PST)
Local: Wed 4 Nov 2009 03:05
Subject: Re: last item of each day
On Nov 3, 6:43 pm, NickPick <dickreu...@yahoo.com> wrote:

Sorry, I had the WHERE and GROUP BY clauses swapped. Perils of pasting
untested code!

The WHERE condition as given seems to have a bug where only part of
the oldest day is considered. Try: WHERE `timestamp` >= CURDATE() -
INTERVAL 30 DAY -- this also has the benefit of being an indexable
range condition.

(Also, you might reconsider the column name timestamp, being the name
of a type.)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew C.  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 06:42
Newsgroups: comp.databases.mysql
From: "Andrew C." <nonse...@totally.made.up>
Date: Wed, 4 Nov 2009 06:42:29 -0000
Local: Wed 4 Nov 2009 06:42
Subject: Re: last item of each day

"NickPick" <dickreu...@yahoo.com> wrote in message

news:57ccc1f9-f307-4a7b-ad11-de2db0287953@m38g2000yqd.googlegroups.com...

>I have a list with entries and each entry has a timestamp. I'd like to
> show that last entry of each day only, for the last 30 days. How can I
> do this?

> Any help is appreciated

I find it counter-intuitive that a query of the following form doesn't work:

SELECT *, MAX(tstamp) FROM tbl GROUP BY DATE(tstamp);

In my ideal-world imagination, MySQL would provide the '*' from the same row
as it found the 'MAX(tstamp)'.

Alas! ;-)

A.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erick T. Barkhuis  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 07:07
Newsgroups: comp.databases.mysql
From: "Erick T. Barkhuis" <erick.use-...@ardane.c.o.m>
Date: 4 Nov 2009 07:07:46 GMT
Local: Wed 4 Nov 2009 07:07
Subject: Re: last item of each day
Andrew C.:

I think now it's my turn to say: you want the Strawberry Query.
http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-r...

--
Erick

"The secret of success is sincerity. Once you can fake that, you've got
it made."


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NickPick  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 12:42
Newsgroups: comp.databases.mysql
From: NickPick <dickreu...@yahoo.com>
Date: Wed, 4 Nov 2009 04:42:49 -0800 (PST)
Local: Wed 4 Nov 2009 12:42
Subject: Re: last item of each day
On Nov 4, 3:05 am, toby <t...@telegraphics.com.au> wrote:

This only outputs the last value of today for some reason... Any idea
what could be the problem?

thanks


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Captain Paralytic  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 13:49
Newsgroups: comp.databases.mysql
From: Captain Paralytic <paul_laut...@yahoo.com>
Date: Wed, 4 Nov 2009 05:49:37 -0800 (PST)
Local: Wed 4 Nov 2009 13:49
Subject: Re: last item of each day
On 4 Nov, 12:42, NickPick <dickreu...@yahoo.com> wrote:

Erick has pointed you at the correct answer.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew C.  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 08:23
Newsgroups: comp.databases.mysql
From: "Andrew C." <nonse...@totally.made.up>
Date: Thu, 5 Nov 2009 08:23:28 -0000
Local: Thurs 5 Nov 2009 08:23
Subject: Re: last item of each day

"Erick T. Barkhuis" <erick.use-...@ardane.c.o.m> wrote in message
news:7lcni1F3avijjU1@mid.individual.net...

Me? No, I don't want it... You'll have to find someone else who wants it...
;-)

A.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
strawberry  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 20:23
Newsgroups: comp.databases.mysql
From: strawberry <zac.ca...@gmail.com>
Date: Thu, 5 Nov 2009 12:23:16 -0800 (PST)
Local: Thurs 5 Nov 2009 20:23
Subject: Re: last item of each day
On Nov 4, 7:07 am, "Erick T. Barkhuis" <erick.use-...@ardane.c.o.m>
wrote:

Ah, but which one IS the strawberry query? ;-)

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erick T. Barkhuis  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 20:33
Newsgroups: comp.databases.mysql
From: "Erick T. Barkhuis" <erick.use-...@ardane.c.o.m>
Date: 5 Nov 2009 20:33:06 GMT
Local: Thurs 5 Nov 2009 20:33
Subject: Re: last item of each day
strawberry:

Nobody knows.
It's one of the best-kept secrets of this group. Many have already
tried to discover the Real Strawberry Query, but the efforts have been
unsuccessful so far....and very likely, so will they be in the future.

Of course, there's plenty of imitation stuff around.

--
Erick


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google