RE: cheapest way to access every 15th row in table ordered by timestamp column
- From: <Dominic.Brooks@xxxxxxxxxxxxxxxxxxx>
- To: <Chris.Stephens@xxxxxxx>, <oracle-l@xxxxxxxxxxxxx>
- Date: Wed, 19 Jan 2011 16:32:06 +0000
What's the definition of every 15th row? Ordered by anything?
NTILE (#buckets) OVER () is an alternative, not necessarily more efficient as
what's there is pretty efficient already (only question is the ordering prior
to rownum).
________________________________
From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx] On
Behalf Of Stephens, Chris
Sent: 19 January 2011 16:20
To: ORACLE-L
Subject: cheapest way to access every 15th row in table ordered by timestamp
column
11.2.0.2 on Linux 5
We have a lab instrument recording information every 2 seconds into a table.
The scientists pull that data into excel for analysis (I hope to look at this
excel spreadsheet in the very near future now that I've read chapter 9 of Pro
Oracle SQL).
They are requesting a view that picks out every 15th row of data going back 30
days.
Can anyone think of a more efficient way to do it than this:
SELECT x.col,
x.t_stamp
FROM ( SELECT col,
t_stamp
rownum rn
FROM t
WHERE t_stamp >= TRUNC( SYSDATE - 30 )) x
WHERE MOD( x.rn, 15 ) = 0;
It feels like there should be a better way to do it.
chris
CONFIDENTIALITY NOTICE:
This message is intended for the use of the individual or entity to which it is
addressed and may contain information that is privileged, confidential and
exempt from disclosure under applicable law. If the reader of this message is
not the intended recipient or the employee or agent responsible for delivering
this message to the intended recipient, you are hereby notified that any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify us
immediately by email reply.
_______________________________________________
This e-mail may contain information that is confidential, privileged or
otherwise protected from disclosure. If you are not an intended recipient of
this e-mail, do not duplicate or redistribute it by any means. Please delete it
and any attachments and notify the sender that you have received it in error.
Unless specifically indicated, this e-mail is not an offer to buy or sell or a
solicitation to buy or sell any securities, investment products or other
financial product or service, an official confirmation of any transaction, or
an official statement of Barclays. Any views or opinions presented are solely
those of the author and do not necessarily represent those of Barclays. This
e-mail is subject to terms available at the following link:
www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the
foregoing. Barclays Capital is the investment banking division of Barclays
Bank PLC, a company registered in England (number 1026167) with its registered
office at 1 Churchill Place, London, E14 5HP. This email may relate to or be
sent from other members of the Barclays Group.
_______________________________________________
Other related posts: