Date range windowing query...I think
Trying to do something I've not done before perhaps you can help or point me in the right direction.
I've got a simple table with events, something like name, start_date, end_date. These events can be duplicates, they can be distinct, they can have the same start_date and different names, or they can have the same name and start_date but different end_dates - any kind of overlap is allowed. There can also be gaps in the events where there is no event that covers a particular date. Really the only thing I can count on is that none of the values will be null. Basically a mess, as far as determining into which event's start-end date range a particular date falls, when there is overlap. However, that's what I need to do. The other wrinkle is that it's okay for me to ignore the end date of an event, for the purposes of gap-filling. That is to say, if there is no event that covers Jun 1, 2010, then I can 'choose' the event that ends prior to Jun 1, 2010.
I would like to, assuming some analytic function magic that I don't have, take this table and produce another that recomputes the start and end dates so that there is no overlap and the gaps are filled. As an overly simplistic example, given the input:
name start end
foo1 jan 1 jan 31
foo2 jan 15 jan 31
foo3 mar 1 mar 30
it would generate
foo1 jan 1 feb 28
foo3 mar 1 mar 30
or, alternatively
foo1 jan 1 jan 14
foo2 jan 15 feb 28
foo3 mar 1 mar 30
almost any reasonable elimination of overlaps is okay, so long as it makes sense. Are there any of the analytic functions that make this less painful?
I'm not sure what the PK of your table is and how "funny" the data can get, but your second result can be got by this:
create table test1 (
name varchar2(10),
startd date,
endd date);
insert into test1 values('foo1', to_date('20100101','yyyymmdd'),to_date('20100131','yyyymmdd'));
insert into test1 values('foo2', to_date('20100115','yyyymmdd'),to_date('20100131','yyyymmdd'));
insert into test1 values('foo3', to_date('20100301','yyyymmdd'),to_date('20100330','yyyymmdd'));
commit;
select name,to_char(startd,'mon dd') startd,
to_char(lead(startd -1,1,endd) over (order by startd),'mon dd')endd
from test1
order by startd;
or, alternatively
foo1 jan 1 jan 14
foo2 jan 15 feb 28
foo3 mar 1 mar 30foo1 jan 01 jan 14
foo2 jan 15 feb 28
foo3 mar 01 mar 30
- andy
Similar Messages
-
Error when selecting date range in query designer
hi all,
when iam trying to select date range in query designer like 01.04.2009 to 10.04.2009 it has to select only that dates where as it is selecting all the dates in between those like 010.04.2009,01.03.2009,01.02.2009.why this is happening ,iam unable to understand.plzz help me in this issue.
Vamshi D Krishnahi ,
i have created a variable as you told but no use.still i have to select the dates manuallyone after the other.for more user friendly can i have a calander where i can select date ranges.is it posible to have calander for selecting date ranges instead selecting dates one by one,if posible i request you to give the detailed steps.plzz guide me in this issue.thanks in advance.
Vamshi D Krishna -
Hi All,
We have created a query report which we have created as a stored procedure and we are executing the sp in SBO to get the result. However, there is one issue, we have passed the variables in the sp as well as the fms to get the date range, but if we input the date manually, the result shown is incorrect!!
It works fine when we tab on the from date, scroll down and select the date from the cfl!! This is not acceptable to the client. They want to enter the dates manually and not select from the cfl.
Please advise what is wrong here and how to correct this issue?? Is there any limitation of this sort..
Thanks,
JosephHi Joseph,
Instead of getting the date as string, try by changing the below declaration part
Declare @datefrom VARCHAR(20)
DECLARE @dateto VARCHAR(20)
by this
Declare @datefrom datetime
DECLARE @dateto datetime
I think, then you need to chenge the same in the SP too
Regards,
Bala -
Visual Composer: Date Range in Query
Hi,
While working in Visual Composer, I have come across the need to re-use the same query 20 times, but with slightly different date ranges. One way would be to create 20 copies of the same query and change the selection dates as needed on each of them. However, is it possible to provide date ranges in a query in Visual Composer? Right now its only letting me enter single values.
Thanks
AdeelProblem can be resolved by using a colon between the dates. Furthermore, the DSTR function in the expression editor can be used to form the desired dates.
-
Hi,
Is the keydate in query accepts the date range, from the query properties keydate accepts one date. I also tried from variable customer exit it is giving an error shown below.
EError for variable in customer enhancement <variable name>
EVariables contain invalid values.
I>> Row: 82 Inc: LRRMSU13 Prog: SAPLRRMS
ASystem error in program CL_RSR_OLAP_VAR and form INIT-02- (see long text)
The requirement is to display multiple records from master data (the time dependent master data in the given data range) based on the keydate range provided.
Please respond how to resolve this.
Thanks
Sreedh.Hi Shalabh,
Here is the output i'm looking for
Time dependent Master data
Emp1 date from date to Attr1 Attr2
ABCD 01/01/2008 02/29/2008 Name1 Name2
ABCD 03/01/2008 05/31/2008 Name3 Name4
In query when the key date is >= 01/01/2008, the trsn data will show as
Emp1 Attr1 Attr2 Keyfig
ABCD Name1 Name2
ABCD Name3 Name4 30
The keydate for the query is not accepting the range, is there anyway to achieve this. Don't want to use the Infoset.
Thanks
Sreedh -
Discoverer Date Range Union Query
Hi All,
I need your help in creating a discovere report in version 11G.
Following Report find missing elimination account based on Transaction done in a date Range. Find out how many accounts are not defined in Elimination Account Setup. Following query gives me desired output but i am having hard time creating a discoverer report for Date Range Parameter as Date Range only applied to one side of union.
In First Query i used decode with sysdate itself so that i can use effective_date as parameter and second side i just kept sysdate.
PLease let me know how can i create a parameterized report for effective_date range.
SELECT
/*+ ORDERED
USE_NL(jel jeh jeb cat src)
INDEX(jel GL_JE_LINES_N1)
INDEX(jeh GL_JE_HEADERS_U1)
INDEX(jeb GL_JE_BATCHES_U1)
INDEX(cat GL_JE_CATEGORIES_TL_U1)
INDEX(src GL_JE_SOURCES_TL_U1) */
CC.SEGMENT1
||'.'
||CC.segment2
||'.'
||CC.segment3
||'.'
||cc.segment4
||'.'
|| cc.segment5
||'.'
|| cc.segment6 Account,
decode(sysdate,sysdate,sysdate,jel.effective_date) trx_date
FROM gl_code_combinations cc,
gl_je_lines jel,
gl_je_headers jeh,
gl_je_batches jeb,
gl_je_categories cat,
gl_je_sources src
WHERE cc.CHART_OF_ACCOUNTS_ID = 50308
AND cc.segment2 IN ('111710','201910')
AND jel.code_combination_id = cc.code_combination_id
AND jel.status
|| '' = 'P'
AND (jel.accounted_cr != 0
OR jel.accounted_dr != 0)
AND jeh.je_header_id = jel.je_header_id
AND jeh.actual_flag = 'A'
AND jeh.currency_code != 'STAT'
AND jeb.je_batch_id = jeh.je_batch_id
AND jeb.average_journal_flag = 'N'
AND src.je_source_name = jeh.je_source
AND cat.je_category_name = jeh.je_category
and jel.effective_date between to_date('01-JAN-2011','DD-MON-RRRR') and to_date('31-MAY-2011','DD-MON-RRRR')
MINUS
SELECT (source_segment1
||'.'
||source_segment2
||'.'
||source_segment3
||'.'
||source_segment4
||'.'
||source_segment5
||'.'
||source_segment6) def_acnt,
sysdate
FROM GL_ELIM_ACCOUNTS_MAPHi,
You can use the following SQL to get the effective date into the SQL and by that create the condition in the report:
SELECT
CC.SEGMENT1
||'.'
||CC.segment2
||'.'
||CC.segment3
||'.'
||cc.segment4
||'.'
|| cc.segment5
||'.'
|| cc.segment6 Account,
decode(sysdate,sysdate,sysdate,jel.effective_date) trx_date,
jel.effective_date
FROM gl_code_combinations cc,
gl_je_lines jel,
gl_je_headers jeh,
gl_je_batches jeb,
gl_je_categories cat,
gl_je_sources src
WHERE cc.CHART_OF_ACCOUNTS_ID = 50308
AND cc.segment2 IN ('111710','201910')
AND jel.code_combination_id = cc.code_combination_id
AND jel.status
|| '' = 'P'
AND (jel.accounted_cr != 0
OR jel.accounted_dr != 0)
AND jeh.je_header_id = jel.je_header_id
AND jeh.actual_flag = 'A'
AND jeh.currency_code != 'STAT'
AND jeb.je_batch_id = jeh.je_batch_id
AND jeb.average_journal_flag = 'N'
AND src.je_source_name = jeh.je_source
AND cat.je_category_name = jeh.je_category
AND NOT EXISTS (
SELECT 1
FROM GL_ELIM_ACCOUNTS_MAP
WHERE CC.SEGMENT1 = source_segment1
AND CC.segment2 = source_segment2
AND CC.segment3 = source_segment3
AND cc.segment4 = source_segment4
AND cc.segment5 = source_segment5
AND cc.segment6 = source_segment6
AND decode(sysdate,sysdate,sysdate,jel.effective_date) = SYSDATE
*** I removed the hints, but if you need those get them back
*** BTW i didn't understand the logic behind the "decode(sysdate,sysdate,sysdate,jel.effective_date)" wouldn't it always be SYSDATE???
Tamir -
Date range related query needed
I have table 'ratemast' with following columns and data
begindate enddate rate1
01-12-2006 10-12-2006 750.00
11-12-2006 25-12-2006 950.00
26-12-2006 02-03-2007 1500.00
the data in begindate and enddate may fall between any date range.
it may be for a week or for a month or even more than that.
i need a query to do the following:
my query will have begindate and enddate for any date range which is not defined in a single row of ratemast.
I need to pick indiviudal date and its respective rate and sum them and it should be divided by number of days.
eg:- if begindate: 09-12-2006 enddate: 13-12-2006
result should be : (750+750+950+950+950)/5
Please help.Hi,
Here's one way... you may have to alter it to check for count(*) = 0 or any other corner cases.
[email protected](152)> create table ratemast(begindate date, enddate date, rate number);
Table created.
Elapsed: 00:00:00.22
[email protected](152)> insert into ratemast(begindate, enddate, rate)
values (date '2006-12-01', date '2006-12-10', 750);
1 row created.
Elapsed: 00:00:00.01
[email protected](152)> insert into ratemast(begindate, enddate, rate)
values (date '2006-12-11', date '2006-12-25', 950);
1 row created.
Elapsed: 00:00:00.00
[email protected](152)> insert into ratemast(begindate, enddate, rate)
values (date '2006-12-26', date '2007-03-02', 1500);
1 row created.
Elapsed: 00:00:00.00
[email protected](152)> commit;
Commit complete.
Elapsed: 00:00:00.04
[email protected](152)> select * from ratemast
2 /
BEGINDATE ENDDATE RATE
01-DEC-06 10-DEC-06 750
11-DEC-06 25-DEC-06 950
26-DEC-06 02-MAR-07 1500
Elapsed: 00:00:00.03
[email protected](152)> var begin_date varchar2(10);
[email protected](152)> var end_date varchar2(10);
[email protected](152)> exec :begin_date := '2006-12-09';
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
[email protected](152)> exec :end_date := '2006-12-13';
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
[email protected](152)> @ed
Wrote file TEST.BRANDT_152_20070315150352.sql
1 with dates as (
2 select to_date(:begin_date, 'YYYY-MM-DD') + level - 1 as d
3 from dual
4 connect by level <= to_date(:end_date, 'YYYY-MM-DD') - to_date(:begin_date, 'YYYY-MM-DD') + 1
5 )
6 select dates.d
7 , r.rate
8 from dates
9 , ratemast r
10* where dates.d between r.begindate and r.enddate
[email protected](152)> /
D RATE
09-DEC-06 750
10-DEC-06 750
11-DEC-06 950
12-DEC-06 950
13-DEC-06 950
Elapsed: 00:00:00.02
[email protected](152)> ed
Wrote file TEST.BRANDT_152_20070315150352.sql
1 with dates as (
2 select to_date(:begin_date, 'YYYY-MM-DD') + level - 1 as d
3 from dual
4 connect by level <= to_date(:end_date, 'YYYY-MM-DD') - to_date(:begin_date, 'YYYY-MM-DD') + 1
5 )
6 select :begin_date
7 , :end_date
8 , avg(r.rate) as fee
9 from dates
10 , ratemast r
11 where dates.d between r.begindate and r.enddate
12* group by :begin_date
[email protected](152)> /
:BEGIN_DATE :END_DATE FEE
2006-12-09 2006-12-13 870
Elapsed: 00:00:00.01
[email protected](152)> exec :end_date := '2007-01-15';
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
[email protected](152)> @ed
Wrote file TEST.BRANDT_152_20070315151840.sql
1 with dates as (
2 select to_date(:begin_date, 'YYYY-MM-DD') + level - 1 as d
3 from dual
4 connect by level <= to_date(:end_date, 'YYYY-MM-DD') - to_date(:begin_date, 'YYYY-MM-DD') + 1
5 )
6 select dates.d
7 , r.rate
8 from dates
9 , ratemast r
10* where dates.d between r.begindate and r.enddate
[email protected](152)> /
D RATE
09-DEC-06 750
10-DEC-06 750
11-DEC-06 950
12-DEC-06 950
13-DEC-06 950
14-DEC-06 950
15-DEC-06 950
16-DEC-06 950
17-DEC-06 950
18-DEC-06 950
19-DEC-06 950
20-DEC-06 950
21-DEC-06 950
22-DEC-06 950
23-DEC-06 950
24-DEC-06 950
25-DEC-06 950
26-DEC-06 1500
27-DEC-06 1500
28-DEC-06 1500
29-DEC-06 1500
30-DEC-06 1500
31-DEC-06 1500
01-JAN-07 1500
02-JAN-07 1500
03-JAN-07 1500
04-JAN-07 1500
05-JAN-07 1500
06-JAN-07 1500
07-JAN-07 1500
08-JAN-07 1500
09-JAN-07 1500
10-JAN-07 1500
11-JAN-07 1500
12-JAN-07 1500
13-JAN-07 1500
14-JAN-07 1500
15-JAN-07 1500
38 rows selected.
Elapsed: 00:00:00.01
[email protected](152)> ed
Wrote file TEST.BRANDT_152_20070315150352.sql
1 with dates as (
2 select to_date(:begin_date, 'YYYY-MM-DD') + level - 1 as d
3 from dual
4 connect by level <= to_date(:end_date, 'YYYY-MM-DD') - to_date(:begin_date, 'YYYY-MM-DD') + 1
5 )
6 select :begin_date
7 , :end_date
8 , avg(r.rate) as fee
9 from dates
10 , ratemast r
11 where dates.d between r.begindate and r.enddate
12* group by :begin_date
[email protected](152)> /
:BEGIN_DATE :END_DATE FEE
2006-12-09 2007-01-15 1243.42105
Elapsed: 00:00:00.01
[email protected](152)> cheers,
Anthony -
Breaking Date Range in Query...
Hi Friends,
I have a Table which calculates Leaves taken by employees. The Leave Start date and End Date is in Range. i.e. Leave is from say 10th March 2006 to 15th March 2006. I need to generate a report for each day of the Leave. I.e. report needs a record for 10th, 11th,12th,13th,14th,15th. How can I break the date range into individual dates betn that range in a SQL Query..?
thanks a lot,
Jalpan PotaYou can do it with a pipelined function. I have posted Re: Quarters Missing.?? that produces a range of quarters for a given date range. You should be easily able to amend this so that it produces a range of dates. Note that you will need to create a type that is a nested table of dates.
Cheers, APC -
Split dates into date range windows
Hi,
I have a peculiar requirement to create windows for different dates.
For example I have two date ranges (two rows in the table column
Start Date End Date
01-Jan 28-Feb
15-Jan 14-Feb (this starts between the previous date range i.e. 01-Jan to 28-Feb)
I have to split dates in a way so that it creates different windows with start and end date i.e.
Start Date End Date
01-Jan 15-Jan (15Jan because it comes before 28 Feb)
16-Jan 14-Feb ( 14Feb as it comes before 28 Feb)
15-Feb 28-Feb
Is there any sql function which can be used to achieve this? or any help you can provide? Thanks.
-SalmanWelcome to the forum!
Unfortunately you posted to the wrong forum. This forum is for sql developer only.
Repost you question in the SQL and PL/SQL forum and you will get help there.
Please mark this question ANSWERED to people will follow up in the other forum. -
Need to specify date range for query result.
Below is my query. The query as is is working fine. The columns 'totalCalls' , 'totalOrders' and 'totalSCs' are all stored by date. I have created a form where the user can specify a start and end date. How would I change this query to report within those specified dates.
<cfquery name="qZVPData_Western" datasource="xxxxxx">
SELECT UserID,
TMName,
UserZone,
AVG(WeekCallGoal) AS WCG,
AVG(QTCallGoal) AS QTCG,
(SELECT COUNT(*)
FROM Sales_Calls
WHERE Sales_Calls.UserID = u.UserID) as totalCalls,
(SELECT COUNT(*)
FROM Orders
WHERE Orders.UserID = u.UserID) as totalOrders,
(SELECT SUM(Quantity)
FROM ProductOrders PO
WHERE PO.UserID = u.UserID AND PO.NewExisting = 1) as newItems,
(SELECT SUM(NewExisting)
FROM ProductOrders PO_
WHERE PO_.UserID = u.UserID) as totalNew,
(SELECT COUNT(ServiceCall_ID)
FROM ServiceCalls SC
WHERE SC.UserID = u.UserID) as totalSCs,
(SELECT COUNT(UserID)
FROM TMStatusLog TSL
WHERE TSL.UserID = u.UserID AND TSL.Status = 'Vacation') as TSLdays1,
(SELECT COUNT(UserID)
FROM TMStatusLog TSL
WHERE TSL.UserID = u.UserID AND TSL.Status = 'TradeShow') as TSLdays2,
(SELECT COUNT(UserID)
FROM TMStatusLog TSL
WHERE TSL.UserID = u.UserID AND TSL.Status = 'Admin Day') as TSLdays3,
SUM(TSLdays1)+(TSLdays2)+(TSLdays3) AS TSLdays,
SUM(totalOrders)/(totalCalls) AS closePerc,
SUM(totalOrders)/(totalCalls) - (.30) AS GRV,
SUM(totalSCs)+(totalCalls)-(QTCG) AS PerVar,
(SUM(totalSCs) + totalCalls + (TSLdays*WCG/5))/QTCG AS PerCalls
FROM Users u
WHERE UserZone = 'Western'
GROUP BY UserZone, UserID, TMName
</cfquery>
I figured I could add this to the columns WHERE statements;
'AND Column BETWEEN #FORM.Start# AND #FORM.End#' but this isn't working.
Any ideas???What is the SQL being generated by your <cfquery> contents? Is it valid SQL? This is always the first thing to check when you get SQL errors back from the DB... check what you're sending to the DB.
Second: don't hard-code dynamic values into your SQL string, pass them as parameters.
Re all the subqueries: it runs fine in dev. Have you tried to load test it? If poss move your subqueries to the FROM statement, as then they're only run once per recordset. As opposed to once per row of the result set, when the subqueries are in the SELECT or WHERE statement.
Adam -
SQL Syntax for hour/date range in Query
Hi
I am trying to set up an query for sales order documents procesed in the last 30 minutes to be set as an alert to be run every 30 minutes to the sales manager. I am having difficulty getting the syntax for the last 30 minutes
Any suggestions?
Davidhi,
I'm not sure query is correct,but u can modify it futher to get correct one.
SELECT T0.DocNum, T0.DocDate, T0.CardName, T0.DocTotal FROM ORDR T0 WHERE DateDiff(dd, T0.DocDate ,getdate()) = 0 and
DateDiff(Minute,T0.DocTime,' ') <= 30
Jeyakanthan -
Hi Experts,
I have a query that a client want as a Dashboard report. For this report to work in the Add-on, I cannot speficy it like this:
T1.RefDate >= [%0] AND T1.RefDate <= [%1]
Here is the Query they need this for:
SELECT SUM(T0.SYSDeb - T0.SYSCred) AS 'Production'
FROM JDT1 T0
WHERE T0.Account in ('_SYS00000000238','_SYS00000000239','_SYS00000000244')
UNION
SELECT SUM(T0.SYSDeb - T0.SYSCred) AS 'Production'
FROM JDT1 T0
WHERE T0.Account = '_SYS00000000053'
They want this to display for the curent month and have another that shows this for the past month.
Any help would be appreciated.
MarliHi Marli,
Try this for current month:
SELECT SUM(T0.SYSDeb - T0.SYSCred) AS 'Production'
FROM dbo.JDT1 T0
WHERE T0.Account in ('_SYS00000000238','_SYS00000000239','_SYS00000000244', '_SYS00000000053') AND
MONTH(T0.RefDate)=Month(Getdate()) AND YEAR(T0.RefDate)=YEAR(Getdate())
For last month, you just need change to MONTH(T0.RefDate)=Month(Getdate())-1
Thanks,
Gordon -
Date Range Parameter's Restriction
Could you someone please tell me how BO restricts date range parameter when the users tries to run a query? Often times, users simultaneously try to get several years of data dumped into a single query. Some users even forget to enforce the date range, which causes the query to try to get the data from the beginning of time.
How do we as a BO developer create some sort of date range restriction so that it can prevent users from overloading a query? If the users want to get several years of data, he/she has to run a query in batches instead of doing it all at once.
I hope there is a way that we can create a custom informational error message for each report to prevent users from trying to query too many months or years of data. Some reports may hit small and well-indexed tables that allow large date range queries. But, some reports query against large and poorly indexed tables, which can potentially cause adverse effect on performance without date range restriction.
Any thoughts or advices on how to implement such things (if possible). I am also afraid that the answer will be "currently not doable". If so, any ideas if the next version of BO will allow such functionality, or if it is at least in the plan at all? Thank you so much for your insight and sharing. Have a great day!Dear Amr,
Thanks so much for your quick reply! The field I want to create a restriction on is called RESULT_DT_TM. When I saw the "where" section of the field, I just don't see how I can apply my START_DT_TM and END_DT_TM parameters on this field so that START_DT_TM and END_DT_TM cannot be more than 365 days apart. If my query does not use parameters called START_DT_TM and END_DT_TM, this "where" section will not be valid?
I don't think the solution has to be on the field itself but rather on the parameter START_DT_TM and END_DT_TM. What I want is that as long as START_DT_TM and END_DT_TM are more than 365 days apart, it does not matter what field these parameters are running against. The screen would then display something saying "your date range parameters for this report must be within 365 days. Please revise your date range on query".
Sorry, I am PL/SQL report programmer, and not familiar with what BO can do. So, is there anyway that can make my dream come true? Thanks a bunch again, Amr. -
Timestamp data type on S[range C on E] constant value-based range windows
Hello,
My questiong is about how can we use timestamp value on S[range C on E] constant value-based range windows.
I have a LotEvent which i should collect and sum lastQty data for last ten minutes of market time (sendDate)
A normal [range 600] query does not work for me because i would like to use the exact time which data has been generated by the market (sendDate).
Here is the event;
public class LotEvent{
private Double totalQty;
private float lastQty;
private String symbol;
private String messageType;
private Integer dataInterval;
private String sendDate;
send date is always in "MM-dd-yyyy HH:mm:ss" format.
I have tried to use the following query but this gives an error;
Invalid statement: "select symbol, sum(lastQty) as lastQty, 10 AS dataInterval
+from lotInputChannel [range INTERVAL "0 0:0:15.0" DAY TO SECOND on >>sendDate<<]+
group by symbol"
Cause: Datatype char is not valid for value based windows
Action: Use a valid datatype for value based windows>
Here is the CQL;
<?xml version="1.0" encoding="UTF-8"?>
<wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application">
<processor>
<name>lotProcTenMin</name>
<rules>
<query id="tenMin"> <![CDATA[select symbol, sum(lastQty) as lastQty, 10 AS dataInterval
from lotInputChannel [range INTERVAL "0 00:10:00.0" DAY TO SECOND on sendDate]
group by symbol]]> </query>
</rules>
</processor>
</wlevs:config>
i have tried this cql after changing the sendDate data type to long which is the time in milliseconds value but it did not work.
select symbol, sum(lastQty) as lastQty, 10 AS dataInterval
from lotInputChannel [range INTERVAL "0 00:10:00.0" DAY TO SECOND on to_timestamp(sendDate)]
group by symbol
The query above does not work also when sendDate is a String in "MM-dd-yyyy HH:mm:ss" format
At last i tried the following query with sendDate as time in milliseconds (long) value. It works! but i still would like to know how to use timestamp in S[range C on E] queries
select symbol, sum(lastQty) as lastQty, 10 AS dataInterval
from lotInputChannel [range *600000* on sendDate]
group by symbol
public class LotEvent{
private Double totalQty;
private float lastQty;
private String symbol;
private String messageType;
private Integer dataInterval;
private long sendDate;
Could anybody please help me with this issue?
Edited by: user8830791 on 01-Aug-2011 06:39It seems that you should configure the channel "lotInputChannel" as an application timestamped channel.
You can do that as follows -
- Have "sendDate" as a long and let its unit be milliseconds
- Use the following child elements of <channel> for the "lotInputChannel"
<wlevs:application-timestamped is-total-order="true">
<wlevs:expression>sendDate*1000*1000</wlevs:expression>
</wlevs:application-timestamped>
The multiplication by 10^6 is required since the units need to be converted into nanos
With this, you could use the query -
select symbol, sum(lastQty) as lastQty, 10 AS dataInterval
from lotInputChannel [range 10 minutes]
group by symbol
Of course, for the above to work, a requirement is that the value of "sendDate" is non-decreasing.
That is if e1 is before e2 in the "lotInputChannel" then e1.sendDate <= e2.sendDate
Edited by: Anand Srinivasan on Aug 2, 2011 6:57 AM -
Analytic functions using window date range
Here are my requirements:
For each FLT# Get the MIN and MAX CRSG_DT within 2½ hours period into the same bucket for each day
I am using Oracle 10gR2
CREATE TABLE TST_ANAL
FLT_NBR VARCHAR2(10),
CRSG_DT DATE ,
TNBR VARCHAR2(14)
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:31:57 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013438');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 08:31:02 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013446');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:30:34 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013440');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:32:07 PM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013427');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:32:40 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013433');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 05:35:40 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013429');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:32:45 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D2007070013434');
INSERT INTO TST_ANAL ( FLT_NBR, CRSG_DT, TNBR) VALUES (
'0002947', TO_Date( '03/01/2007 07:32:50 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'D200707001323');
COMMIT;
The desired output:
FLT_NBR CRSG_DT MIN MAX Bucket
2947 3/1/2007 5:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 5:35 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 7:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 7:32 3/1/2007 5:32 3/1/2007 7:32 1
2947 3/1/2007 17:30 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 17:32 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 19:31 3/1/2007 17:30 3/1/2007 19:31 2
2947 3/1/2007 20:31 3/1/2007 20:31 3/1/2007 20:31 3
I am sure an Analytic query is the optimal solution. I need help creating the query. So far, I have attempted to use the min() and then both First_value() over partition clause but I do not know how to specify the window clause using a logical date range to calculate the 2 1/2 hours.
A lot of documentation states that I can use an expression for the range between but I cannot get one even compile
Need Help or documentation that provide some assistance
ThanksI can get to the min and max, but for bucket, row_number() doesn't take the same windowing logical offset.
SQL> select flt_nbr,
2 crsg_dt,
3 min(crsg_dt) over (partition by flt_nbr,
4 trunc(crsg_dt)
5 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mn,
6 max(crsg_dt) over (partition by flt_nbr,
7 trunc(crsg_dt)
8 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mx
9 from tst_anal
10 /
FLT_NBR CRSG_DT MN MX
0002947 01-MAR-2007 05:32:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 05:35:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 07:32:45 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 07:32:50 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50
0002947 01-MAR-2007 17:30:34 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57
0002947 01-MAR-2007 17:32:07 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57
0002947 01-MAR-2007 19:31:57 01-MAR-2007 17:30:34 01-MAR-2007 20:31:02
0002947 01-MAR-2007 20:31:02 01-MAR-2007 19:31:57 01-MAR-2007 20:31:02
8 rows selected.
SQL> Had to user FIRST_VALUE and then calculate row_number() on that for bucket.
SQL>
SQL> select flt_nbr, crsg_dt, mn, mx, dense_rank() over (partition by flt_nbr,
2 trunc(crsg_dt)
3 order by rn) bucket
4 from (select flt_nbr,
5 crsg_dt,
6 min(crsg_dt) over (partition by flt_nbr,
7 trunc(crsg_dt)
8 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mn,
9 max(crsg_dt) over (partition by flt_nbr,
10 trunc(crsg_dt)
11 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) mx,
12 FIRST_VALUE(crsg_dt) over (partition by flt_nbr,
13 trunc(crsg_dt)
14 order by crsg_dt range between (2.5/24) preceding and (2.5/24) following) rn
15 from tst_anal)
16 /
FLT_NBR CRSG_DT MN MX BUCKET
0002947 01-MAR-2007 05:32:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 05:35:40 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 07:32:45 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 07:32:50 01-MAR-2007 05:32:40 01-MAR-2007 07:32:50 1
0002947 01-MAR-2007 17:30:34 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57 2
0002947 01-MAR-2007 17:32:07 01-MAR-2007 17:30:34 01-MAR-2007 19:31:57 2
0002947 01-MAR-2007 19:31:57 01-MAR-2007 17:30:34 01-MAR-2007 20:31:02 2
0002947 01-MAR-2007 20:31:02 01-MAR-2007 19:31:57 01-MAR-2007 20:31:02 3
8 rows selected.
SQL> Cheers
Sarma.
Maybe you are looking for
-
I am new to unix , i want to know - how to check filesystem SAN / NFS & total free space in system.
-
How to calculate a cumulative total in HANA
Hello, I have a detail table (e.g. GL line item table) which has entries for 'posting date', account number, year, month, posting amount (single key figure) and account type (whether the account is a profit & loss account or a balance sheet account.
-
Insert operation takes looooooooooong time
One of our ETL procedures does an Insert operation on a table with the records selected from a couple of tables across DB link. While the SELECT query takes about 6 seconds to retrieve nearly 42,00,000 records, the insert of those records to a table
-
Hi all, Why do we create personnel areas and personnel sub-areas in Human resource under Enterprise structure, while the company, company code and location is created by Finance consultants.......i felt like there is a reason
-
Adding third domain controller - decommissioning one existing
Hello, I would like to add a new 2012 domain controller to site A which already has a 2008 domain controller. There is also another site B with has an existing 2012 domain controller. I have a couple questions. When I add the new domain controller