Link to home
Create AccountLog in
Avatar of Jerry N
Jerry NFlag for United States of America

asked on

Inserting transaction data into various time related tables

I have posted this question and received an answer, however I now have a new problem. Here;s the original question:
---------
I have a table that has trading transactions and contains a timestamp field and a ASK price each time the price changes (tick data).
The timestamp has the format:1/1/2009 10:42:00.000000 PM
The records are sequential but do not have a consistent gap. some are the same time, some are 2 seconds apart, some 10 seconds apart.
I wish to load  the beginning ask price and the ending ask price for each minute into another table (MIN_Table)

-------
The answer that worked great:
SELECT   TO_CHAR (ticktime, 'dd/mm/yyyy hh24:mi'),
           Min(ASK) Min,
           Max(ASK) Max,
           MAX (ask) KEEP (DENSE_RANK FIRST ORDER BY id) Open,
           MAX (ask) KEEP (DENSE_RANK LAST ORDER BY id)  Close
    FROM   Ticktemp
GROUP BY   TO_CHAR (ticktime, 'dd/mm/yyyy hh24:mi');
------
I place this into an INSERT INTO statement and this works for a table containing 1 minute transactions.
I can also make this work for a 1 hour table (thanks to help here) by changing the TO_CHAR to hh24:hh24

But I need to be able to generate data to fill the following individual tables:
1 min (got it)
5 min
15 min
30 min
1 hour(got it)
4 hours
1 day
1 week
1 month.

Does anyone have a solution for the other time frame tables that I can use in an insert statement?
ASKER CERTIFIED SOLUTION
Avatar of htonkov
htonkov

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Jerry N

ASKER

Excellent - thanks so much! worked like a charm
Avatar of Jerry N

ASKER

If you're still around, I have a question.
Should the week be tunc(ticktime,'WW')?  When I run it today with 'W', it gives me yesterday's date (tuesday), if I run it wilt 'WW' it gives me last saturday's date.


Avatar of htonkov
htonkov

Oops, yes you are right...

According to
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions230.htm#i1002084

it seems that you might try trunc(ticktime,"D") , I don't have oracle at hand right now, but it says that it should trunc to starting day of week (sunday or monday, depending on your NSL settings)
Avatar of Jerry N

ASKER

ah, but how would I do a weekly where the where the week starts on a certain day, i.e. Sunday, no mater where the year started?
If you use "D" it does not depend on day when week started but it depends on how is first day of week defined (i.e. sunday or monday) as configured in your oracle system.

Check

http://download.oracle.com/docs/cd/E11882_01/server.112/e25513/initparams153.htm#REFRN10128
http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/ch3globenv.htm#i1006753

about parameter NLS_TERRITORY