Grouping totals by date ranges
Hi All,
I have an ASP.NET application, in which I have to get totals from a table using different criteria, which I do like this:
SELECT DISTINCT
SUM(CASE WHEN MYCONDITION1 THEN 1 ELSE 0 END) AS TOTAL1,
SUM(CASE WHEN MYCONDITION2 THEN 1 ELSE 0 END) AS TOTAL2
FROM TABLE1, TABLE2
WHERE COMMON_CONDITION1 AND COMMON_CONDITION2
AND BETWEEN DATE1 AND DATE2;
This works fine and I get the intended result.
Now, I have to repeat this for every week for the last 12 months, excluding holidays period. So, I generate a set of date ranges which will be used in the queries. So, I repeat the above sql statement for all the date ranges, which is a lengthy process.
I have to get the totals for every week. For example from 26-Sep-2010 to 02-Oct-2010, 19-Sep-2010 to 25-Sep-2010, 12-Sep-2010 to 18-Sep-2010, etc.. How should I put those ranges in the group by and select statement, because, I don't have them in a table.
How can I do that in a single shot and get all totals for each date range. Please help me with sql.
Thank you.
Edited by: 800729 on Oct 7, 2010 4:33 AM
Hi,
Welcome to the forum!
800729 wrote:
Hi All,
I have an ASP.NET application, in which I have to get totals from a table using different criteria, which I do like this:
SELECT DISTINCT
SUM(CASE WHEN MYCONDITION1 THEN 1 ELSE 0 END) AS TOTAL1,
SUM(CASE WHEN MYCONDITION2 THEN 1 ELSE 0 END) AS TOTAL2
FROM TABLE1, TABLE2
WHERE COMMON_CONDITION1 AND COMMON_CONDITION2
AND BETWEEN DATE1 AND DATE2;Does that really work? Don't you have to do something like
AND date_column BETWEEN DATE1 AND DATE2Post actual code, simplified if necessary, but still something that you can run.
This works fine and I get the intended result.
Now, I have to repeat this for every week for the last 12 months, excluding holidays period. So, I generate a set of date ranges which will be used in the queries. So, I repeat the above sql statement for all the date ranges, which is a lengthy process.
I have to get the totals for every week. For example from 26-Sep-2010 to 02-Oct-2010, 19-Sep-2010 to 25-Sep-2010, 12-Sep-2010 to 18-Sep-2010, etc.. How should I put those ranges in the group by and select statement, because, I don't have them in a table.Are you saying your current query produces 1 row, but you want something that has 53 rows, one for each week in the last year?
If so, add a "GROUP BY x" clause, as Sabnkar suggested, where x is a distinct value for each week.
You will probably *not" want to use TO_CHAR (date_column, 'WW'), especially if all of the output is not in the same calendar year.
If your weeks always begin on Sunday, then TRUNC (date_column, 'D') would be a better GROUP BY exptression, but it depeneds on your NLS settings.
GROUP BY TRUNC (date_column + 1, 'IW') - 1 will do the same thing, regardless of your NLS settings.
You may not need a table tha has one row per week, but if you do, Sauhik showed you how to generate a result set that will work just as well.
How can I do that in a single shot and get all totals for each date range. Please help me with sql.I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data, as Saubhik requested.
Include examples of holidays: it's very unclear how you want to handle them. What is a "holday period"? How do you know if a given date is in one or not?
Simplify the problem as much as possible. For example, post a problem that gets the last 3 weeks, instead of the last 53 weeks. Anyone who suggests a solution will show you how to change it for 53 weeks, if necessary.
Similar Messages
-
Group by with date range.
Hi,
I am looking for effective usage of Group by against date range.
I have a transaction table as below.
Date customer_no amount_paid
01-Dec-13 001 500
02-Dec-13 001 360
09-Dec-13 001 200
02-Nov-13 001 360
09-Nov-13 001 200
02-Nov-13 001 360
09-Oct-13 001 200
02-Oct-13 001 360
09-Oct-13 001 200
02-Sep-13 001 360
09-Sep-13 001 200
............... etc.
I would like to see sum(amount_paid) by past date ranges 1-30 days, 31-60 days, 61-90 days.
Below are expected results.
Customer Duration amount_paid
001 1-30 980
001 31-60 450
001 61-90 1200
002 1-30 300
002 31-60 490
002 61-90 320
003 1-30 450
......................etc.
I have to group by customer no and date range (1-30, 31-60, 61-90..etc).
Can someone help me getting query for this.
Thanks...
Sreeram.SQL> with t
2 as
3 (
4 select to_date('01-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 500 amount_paid from dual
5 union all
6 select to_date('02-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
7 union all
8 select to_date('09-Dec-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
9 union all
10 select to_date('02-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
11 union all
12 select to_date('09-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
13 union all
14 select to_date('02-Nov-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
15 union all
16 select to_date('09-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
17 union all
18 select to_date('02-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
19 union all
20 select to_date('09-Oct-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
21 union all
22 select to_date('02-Sep-13', 'dd-Mon-rr') dt, '001' customer_no, 360 amount_paid from dual
23 union all
24 select to_date('09-Sep-13', 'dd-Mon-rr') dt, '001' customer_no, 200 amount_paid from dual
25 )
26 select customer_no
27 , ((grp_val - 1) * 30) + 1 start_val
28 , grp_val * 30 end_val
29 , sum(amount_paid) amount_paid
30 from (
31 select dt
32 , customer_no
33 , amount_paid
34 , ceil(sum(dt_interval) over(partition by customer_no order by dt)/30) grp_val
35 from (
36 select dt
37 , customer_no
38 , amount_paid
39 , nvl(dt - lag(dt) over(partition by customer_no order by dt), 1) dt_interval
40 from t
41 )
42 )
43 group
44 by customer_no
45 , grp_val
46 order
47 by grp_val;
CUS START_VAL END_VAL AMOUNT_PAID
001 1 30 560
001 31 60 760
001 61 90 920
001 91 120 1060
SQL> -
Formula help - Group totals for more than one date range
Post Author: melcaylor
CA Forum: Formula
I need to show in 3 columns
inside of a grouping that totals an amount field based on a date
range that amount was posted. So for example:
Billy Bob in the state of MA made $5.5m total, $800k in the last 21 days, $400k in the last 14 days and $150k in
the last 7 days.
I assume this is possible but I
just donu2019t know what type of formula to write to make it work. For this
example, there are 2 tables u2013 user table and $$ table. The User table has
the user name, the $$ table has the pay date and the amount.Post Author: SKodidine
CA Forum: Formula
You only need simple formulae in Running Totals to accomplish this.
1. Group by Name
2. Create the following Running Totals:
2.1 A running total to sum the pay amount for all records, and resets on 'Change of Group' of Name.
2.2 A running total to sum the pay amount and for 'Evaluate' click on the radio button next to 'Use a formula' and then click on X-2 button next to it.
In the formula workshop window type a formula such as: {table.payment_date} in (currentdate - 21) to currentdate;
For 'Reset' click on the radio button next to 'On change of group' and pick the group name.
2.3 Create another running total just as in step 2.2 above but change the formula to: {table.payment_date} in (currentdate - 14) to currentdate;
2.4 Create the last running total just as in step 2.2 above but change the formula to: {table.payment_date} in (currentdate - 7) to currentdate;
Hide the details section and in the group footer place text boxes with appropriate text and insert these running totals to give you the numbers you want.
The only issue I see with this is if a person was paid yesterday a sum of $25, then it will show $25 for total, last 7days, last 14days and also for last 21days. At first look it might be mistaken for $75. -
Different totals based on dates (month vs date range)
I know I've seen this before, but I can't find the thread. I have a column in a fact table for price. When I add price and the month (eg April 2012) from the time dimension, it totals one number, but when I remove the month, and add a date range (4/1/2012 - 4/30/2012) it totals another (lower value). I can't find the solution I found last time.
Anyone else run into this? and solve it?RiZapata wrote:
I know I've seen this before, but I can't find the thread. I have a column in a fact table for price. When I add price and the month (eg April 2012) from the time dimension, it totals one number, but when I remove the month, and add a date range (4/1/2012 - 4/30/2012) it totals another (lower value). I can't find the solution I found last time.
Anyone else run into this? and solve it?The solution is to understand what OBIEE is doing. If the totals differ, then the definitions are different. You need to troubleshoot to see what the difference is. When you add the month column and the date (so you can see every date) and add the total then, which total does it tie to? Is there rounding? How off are the two totals? That often may give a clue as to what is missing in the lower total. -
Group by week between date range
Hi,
i'm having a table for documents. The documents are received from diffeent dates. I've to calculate number of documents received on weekly basis.
I need an sql to count the number of documents between two given dates grouping by weekly.
My week starts on Sunday and ends with Saturday.
I've tried group by with to_char(documentdate,'IW') , but this will take Monday to Sunday as a week & the incomlete weeks i'm not able to calculate. ie : in the below output the date range 1/28/2007 - 1/31/2007 is not a complete week . ( ie saturday to wednesday)
I need out put should be like this for Date Range: 12/31/2006 to 1/31/2007
week count of documents
12/31/2006 - 1/6/2007 10
1/7/2007 - 1/13/2007 40
1/14/2007 - 1/20/2007 30
1/21/2007 - 1/27/2007 20
1/28/2007 - 1/31/2007 10
Please help me to get this.....
(columns in documents table is documentid and documentdate)your're very close with IW. you just need to shift the data to get it to fall within the correct range. btw, you don't need julian dates. it's overkill
trunc(date+1,'IW') will push the date into the correct week range (IW will put sunday one week earlier than you want, so push it ahead a day before truncating).
then subtract 1 day from the result to get it to display with sunday's date instead of monday
trunc(mydate+1, 'IW')-1
and the week end date is simply trunc(mydate+1, 'IW')_5
select mydate, to_char(mydate,'Dy') dy,
trunc(mydate+1,'IW')-1 wk_Start,
trunc(mydate+1,'IW')+5 wk_end
from (select sysdate-rownum mydate from dual connect by level < 20)
order by 1 -
Find totals of a date range and sum
How do I find totals between a date range like from 0 up to 60 days from today, 61 to 90 days from today, 91-120 days, 120 and above. Please advise.
Do I use a Add_Months function to convert to days?Try this,
This may help you
SQL> select sysdate,sysdate+interval '60' day from dual;
SYSDATE SYSDATE+INTERVAL'60'DAY
5/5/2008 2: 7/4/2008 2:17:16 PM
SQL>G. -
Group By element ID and continuous date range as a single row - URGENT!!!!
Hi All,
I have a source table and a target table.
Source Table Target Table
Element ID Period_dt Element ID Effective date End date
DD001 200901 DD001 200901 200903
DD001 200902 DD001 200906 200908
DD001 200903 DD002 200801 200803
DD001 200906
DD001 200907
DD001 200908
DD002 200801
DD002 200802
DD002 200803
I want the result as in the target table. Basically, continuous date range should be grouped and shown as single row even it falls under the same elment_id.
I have tried the LAG and LEAD function and RANK function as well but unsuccessful.
I was able to get like this in the target table using MIN and MAX function.
DD001 200901 200908
DD002 200801 200803
For DD001, you can see there is a break in the months. 200901 - 200903 and 200906 - 200908. we are missing 4th,5th month. 1 to 3rd month and 6th to 8th month should be grouped and shown as separate rows in the target table for the same DD001 element_ID
I will post the SQL query tommorrow. Please give your suggestions.
Regards
BalajiThanks guys. It worked perfectly. I apologize for using the 'U' word. This is my first post here.
select prod_element_cd,
min(period_dt) effective_date,
max(Last_day(period_dt)) end_date,
SUM(Fixed_factor),
SUM(var_factor),
val1
from (
select prod_element_cd, period_dt,Fixed_factor,var_factor, val, last_value(val ignore nulls) over(partition by prod_element_cd order by period_dt) val1
from (
select prod_element_cd,
period_dt,
NVL(Fixed,0) Fixed_factor,
NVL(variable,0) var_factor,
lag(period_dt) over(partition by prod_element_cd order by period_dt) dt,
case when add_months(period_dt,-1) = lag(period_dt) over(partition by prod_element_cd order by period_dt)
then null
else rownum end val
from pmax_land.TMP_COST_CASH_STD_INPUT)
group by prod_element_cd, val1
order by prod_element_cd
The above query pulls the below result
PROD_ELEMENT_CD EFFECTIVE_DATE END_DATE FIXED VARIABLE VAL1
DDA001 01/01/2009 03/31/2009 4.20 7.62 1.00
DDA001 06/01/2009 11/30/2009 4.80 0.72 10.00
DDA001 01/01/2010 01/31/2010 0.75 0.50 13.00
DDA002 07/01/2008 09/30/2008 2.40 0.36 11.00
DDA002 02/01/2008 03/31/2008 1.50 1.00 14.00
one more logic added to the requirement
for each occurance, for eg: DDA001, the last row of DDA001 should be taken and the end_date of that should be hardcoded to 12/31/9999
here we have two cases
last row for DDA001 end_date
DDA001 01/01/2010 01/31/2010 0.75 0.50 13.00
end date is 01/31/2010 for this above row of DDA001. It should be hardcoded to 12/31/9999
similarly
last row for DDA002 end_date
DDA002 02/01/2008 03/31/2008 1.50 1.00 14.00
end date is 03/31/2008 for this above row of DDA002. It should be hardcoded to 12/31/9999
Similarly for DDA003,DDA004.......... etc
Thanks for your previous replies. Please give your suggestions.
Regards
Balaji
Edited by: user12119826 on Oct 27, 2009 11:49 PM -
Operation wise total required hours for planned order in given date range
Hello Experts,
My client wants the report to check the capacity utilization of the work centers for the all planned order in particular date range.
Is their any standard report which gives the work center wise operation wise total required hours? or which table should I use to make the customize report so that I will get total required capacity & available capacity.
Thanks in advance for use valuable suggestions.
SagarHi Mario,
Thanks for your reply,
In CM01 or CM05, we are getting requirement on weekly basis.How to get that report on daily basis? I want to give the input as a date range of the planned order.How to go for that?
Edited by: SAGAR GOLIWAR 226 on Jul 3, 2011 8:16 AM -
Grouping by month within date range
Hi,
I have a date range which I like to group by months, but not from the 1st to last date of the calendar month but by given start date. For example the table below represents the date range with some values in a table. So the
first month range in the group should be from 06/06/2013 to 08/07/2013. The 06/07/2013 is absent because it's Saturday. In fact the data is populated with working days only.
Table below shows what I really would like to get:
There is a simple calculation for each month anniversary date, if the value from the start date, 06/06/2013, here 12 is less than the next month anniversary date, 08/07/2013, which is 9, then it should ignore it. And only show the value from the month
who's anniversary date value is less than the first date value, 12. So the example above shows value 14 for the second month's anniversary date, 06/08/2013. If the value has been found in any month the show, and ignore the rest.
I am just interested if there are any and report which number of month and the value.
I can implement this in procedural way, such as in VBA, but because the above looped many times it will take hours to run the process. I have tried in SQL Server, but first problem I came up with is that I can't group by month from the given start
date.
Is this possible to do in T-SQL ?I'm not sure I entirely understand your question. So I'll break the answer into two parts.
First, as I understand it, you are looking for a way to group data by months, but not all dates in June, 2013 as one group, all dates in July, 2013 as the next group, etc. Instead you want all dates from June 6, 2013 to July 5, 2013 as the first month,
all dates from July 6, 2013 to August 5 as the second month etc. The way to do that is use
DATEDIFF(month, '20130606', <your date column>) + CASE WHEN DAY(<your date column>) < 6 THEN -1 ELSE 0 END
So you can assign the month number you want to every row when you select from your table by
SELECT DATE, VALUE, DATEDIFF(month, '20130606', DATE) + CASE WHEN DAY(DATE) < 6 THEN -1 ELSE 0 END AS MonthNumber
FROM <your table name>
Now as I understand it (but am not sure), you want the first value in each "month" (as you are defining "month" which is greater than the value contained in your start date and if no value in a particular month is greater than that value,
you don't want any row for that month. For that you could do something like
Declare @StartDate date;
Declare @StartValue int;
Set @StartDate = '20130606';
Select @StartValue = Value From <your table name>
Where Date = @StartDate;
;With cteMonthNumber As
(SELECT DATE, VALUE, DATEDIFF(month, @StartDate, DATE) + CASE WHEN DAY(DATE) < DAY(@StartDate) THEN -1 ELSE 0 END AS MonthNumber
FROM <your table name>
WHERE DATE > @Date AND VALUE > @Value),
cteOrdered As
(Select DATE, VALUE, MonthNumber,
ROW_NUMBER() OVER (PARTITION BY MonthNumber ORDER BY DATE) As rn
From cteMonthNumber)
Select MonthNumber, Value As KickOutValue
From cteOrdered
Where rn = 1;
Tom
P.S. Notice that I wrote my date literal as YYYYMMDD. This is a good idea in SQL Server since '20130806" will always be interpreted as August 6. But depending on the settings on your server and/or client '06/08/2013' might be dd/mm/yyyy
and so be August 6, but it might be interpreted as mm/dd/yyyy and be June 8.
It is also a good idea to express date literals in this forum as yyyymmdd. There are a lot of us on the forum from the United States and we think 06/08/2013 is June 6 and a lot of us from other places who think 06/08/2013 is Aug 8. If you give
your dates as yyyymmdd we don't have to try to figure out what format you are using. -
Group Above Report problem...not able to display absent rows in date range
In my report query, I have numerous select statements that I must union together and group by a date. The ultimate goal is to get a count for all records in coordination with that date. Then in the report, I group all the data with the same date to ultimately put all counts on a page that coordinate with a single date.
Thing is...if there are no records associated with that date, the 'group by' clause makes the return data set not include those lines of output. I need these lines of output! Any suggestions??
Below is an example...
Select 'Program1', 'SubProgram1', 'Label 1', to_char(receipt_date, 'MM/DD/RRRR'), count(*)
from submissions
where receipt_date between '01-JUN-05' and '10-JUN-05'
and substr(submission_index,8,1) = '3'
and substr(submission_index,9,1) = '1'
group by substr(submission_index,8,1), substr(submission_index,9,1), to_char(receipt_date, 'MM/DD/RRRR')
union
Select 'Program2', 'SubProgram2', 'Label 2',
to_char(receipt_date, 'MM/DD/RRRR'), count(*)
from submissions
where receipt_date between '01-JUN-05' and '10-JUN-05'
and substr(submission_index,8,1) = '4' group by substr(submission_index,8,1), to_char(receipt_date, 'MM/DD/RRRR')
OUTPUT:
Program1 SubProgram1 Label 1 06/01/2005 4
Program1 SubProgram1 Label 1 06/02/2005 2
Program1 SubProgram1 Label 1 06/03/2005 6
Program1 SubProgram1 Label 1 06/04/2005 23
Program1 SubProgram1 Label 1 06/06/2005 71
Program1 SubProgram1 Label 1 06/07/2005 245
Program1 SubProgram1 Label 1 06/08/2005 76
Program1 SubProgram1 Label 1 06/10/2005 45
Program2 SubProgram2 Label 2 06/01/2005 66
Program2 SubProgram2 Label 2 06/02/2005 345
Program2 SubProgram2 Label 2 06/03/2005 89
Program2 SubProgram2 Label 2 06/04/2005 12
Program2 SubProgram2 Label 2 06/05/2005 3
Program2 SubProgram2 Label 2 06/06/2005 27
Program2 SubProgram2 Label 2 06/09/2005 98
Program2 SubProgram2 Label 2 06/10/2005 456
I need the missing lines to show up for Program 1 on 6/05 and 6/09
and Program 2 on 6/07 and 6/08create table your_table (
program varchar2(20),
subprogram varchar2(20),
label varchar2(20),
day date,
num number
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('01-JUN-05'), 4);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('02-JUN-05'), 2);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('03-JUN-05'), 6);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('04-JUN-05'), 23);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('06-JUN-05'), 71);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('07-JUN-05'), 245);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('08-JUN-05'), 76);
insert into your_table values ('Program1', 'SubProgram1', 'Label 1', to_date('10-JUN-05'), 45);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('01-JUN-05'), 66);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('02-JUN-05'), 345);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('03-JUN-05'), 89);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('04-JUN-05'), 12);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('05-JUN-05'), 3);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('06-JUN-05'), 27);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('09-JUN-05'), 98);
insert into your_table values ('Program2', 'SubProgram2', 'Label 2', to_date('10-JUN-05'), 456);
SELECT yt.program
, yt.subprogram
, yt.label
, nvl(yt.num,0) NUM
, days.date_value
FROM ( select (to_date('11-JUN-05','DD-MON-YY') - day) date_value
from ( select rownum day
from dual
connect by rownum < 11
) days
, your_table yt
where yt.day(+) = days.date_value
order by yt.program, days.date_value
PROGRAM SUBPROGRAM LABEL NUM DATE_VALUE
Program1 SubProgram1 Label 1 4 6/1/2005
Program1 SubProgram1 Label 1 2 6/2/2005
Program1 SubProgram1 Label 1 6 6/3/2005
Program1 SubProgram1 Label 1 23 6/4/2005
Program1 SubProgram1 Label 1 71 6/6/2005
Program1 SubProgram1 Label 1 245 6/7/2005
Program1 SubProgram1 Label 1 76 6/8/2005
Program1 SubProgram1 Label 1 45 6/10/2005
Program2 SubProgram2 Label 2 66 6/1/2005
Program2 SubProgram2 Label 2 345 6/2/2005
Program2 SubProgram2 Label 2 89 6/3/2005
Program2 SubProgram2 Label 2 12 6/4/2005
Program2 SubProgram2 Label 2 3 6/5/2005
Program2 SubProgram2 Label 2 27 6/6/2005
Program2 SubProgram2 Label 2 98 6/9/2005
Program2 SubProgram2 Label 2 456 6/10/2005The four null rows will not show up because the date is used at least once between program 1 or program 2. Will there only ever be two programs to chose from? Any one else got any ideas around this? -
Neen help with date range searches for Table Sources
Hi all,
I need help, please. I am trying to satisfy a Level 1 client requirement for the ability to search for records in crawled table sources by a date and/or date range. I have performed the following steps, and did not get accurate results from Advanced searching for date. Please help me understand what I am doing wrong, and/or if there is a way to define a date search attribute without creating a LOV for a date column. (My tables have 500,00 rows.)
I am using SES 10.1.8.3 on Windows 32.
My Oracle 10g Spatial Table is called REPORTS and this table has the following columns:
TRACKNUM Varchar2
TITLE Varchar2
SUMMARY CLOB
SYMBOLCODE Varchar2
Timestamp Date
OBSDATE Date
GEOM SDO_GEOMETRY
I set up the REPORTS table source in SES, using TRACKNUM as the Primary Key (unique and not null), and SUMMARY as the CONTENT Column. In the Table Column Mappings I defined TITLE as String and TITLE.
Under Global Settings > Search Attributes I defined a new Search Attribute (type Date) called DATE OCCURRED (DD-MON-YY).
Went back to REPORTS source previously defined and added a new Table Column Mapping - mapping OBSDATE to the newly defined DATE OCCURRED (DD-MON-YY) search attribute.
I then modified the Schedule for the REPORTS source Crawler Policy to “Process All Documents”.
Schedule crawls and indexes entire REPORTS table.
In SES Advanced Search page, I enter my search keyword, select Specific Source Group as REPORTS, select All Match, and used the pick list to select the DATE OCCURRED (DD-MON-YY) Attribute Name, operator of Greater than equal, and entered the Value 01-JAN-07. Then the second attribute name of DATE_OCCURRED (DD-MON-YY), less than equals, 10-JAN-07.
Search results gave me 38,000 documents, and the first 25 I looked at had dates NOT within the 01-JAN-07 / 10-JAN-07 range. (e.g. OBSDATE= 24-MAR-07, 22-SEP-), 02-FEB-08, etc.)
And, none of the results I opened had ANY dates within the SUMMARY CLOB…in case that’s what was being found in the search.
Can someone help me figure out how to allow my client to search for specific dated records in a db table using a single column for the date? This is a major requirement and they are anxiously awaiting my solution.
Thanks, in advance….raford,
Thanks very much for your reply. However, from what I've read in the SES Admin Document is that (I think) the date format DD/MM/YYYY pertains only to searches on "file system" sources (e.g. Word, Excel, Powerpoint, PDF, etc.). We have 3 file system sources among our 25 total sources. The remaining 22 sources are all TABLE or DATABASE sources. The DBA here has done a great job getting the data standardized using the typical/default Oracle DATE type format in our TABLE sources (DD-MON-YY). Our tables have anywhere from 1500 rows to 2 million rows.
I tested your theory that the dates we are entering are being changed to Strings behind the scenes and on the Advanced Page, searched for results using OBSDATE equals 01/02/2007 in an attempt to find data that I know for certain to be in the mapped OBSDATE table column as 01-FEB-07. My result set contained data that had an OBSDATE of 03-MAR-07 and none containing 01-FEB-07.
Here is the big issue...in order for my client to fulfill his primary mission, one of the top 5 requirements is that he/she be able to find specific table rows that are contain a specific date or range of dates.
thanks very much! -
Need help with date range searches for Table Sources in SES
Hi all,
I need help, please. I am trying to satisfy a Level 1 client requirement for the ability to search for records in crawled table sources by a date and/or date range. I have performed the following steps, and did not get accurate results from Advanced searching for date. Please help me understand what I am doing wrong, and/or if there is a way to define a date search attribute without creating a LOV for a date column. (My tables have 500,00 rows.)
I am using SES 10.1.8.3 on Windows 32.
My Oracle 10g Spatial Table is called REPORTS and this table has the following columns:
TRACKNUM Varchar2
TITLE Varchar2
SUMMARY CLOB
SYMBOLCODE Varchar2
Timestamp Date
OBSDATE Date
GEOM SDO_GEOMETRY
I set up the REPORTS table source in SES, using TRACKNUM as the Primary Key (unique and not null), and SUMMARY as the CONTENT Column. In the Table Column Mappings I defined TITLE as String and TITLE.
Under Global Settings > Search Attributes I defined a new Search Attribute (type Date) called DATE OCCURRED (DD-MON-YY).
Went back to REPORTS source previously defined and added a new Table Column Mapping - mapping OBSDATE to the newly defined DATE OCCURRED (DD-MON-YY) search attribute.
I then modified the Schedule for the REPORTS source Crawler Policy to “Process All Documents”.
Schedule crawls and indexes entire REPORTS table.
In SES Advanced Search page, I enter my search keyword, select Specific Source Group as REPORTS, select All Match, and used the pick list to select the DATE OCCURRED (DD-MON-YY) Attribute Name, operator of Greater than equal, and entered the Value 01-JAN-07. Then the second attribute name of DATE_OCCURRED (DD-MON-YY), less than equals, 10-JAN-07.
Search results gave me 38,000 documents, and the first 25 I looked at had dates NOT within the 01-JAN-07 / 10-JAN-07 range. (e.g. OBSDATE= 10-MAR-07, 22-SEP-07, 02-FEB-08, etc.)
And, none of the results I opened had ANY dates within the SUMMARY CLOB…in case that’s what was being found in the search.
Can someone help me figure out how to allow my client to search for specific dated records in a db table using a single column for the date? This is a major requirement and they are anxiously awaiting my solution.
Thanks very much, in advance….raford,
Thanks very much for your reply. However, from what I've read in the SES Admin Document is that (I think) the date format DD/MM/YYYY pertains only to searches on "file system" sources (e.g. Word, Excel, Powerpoint, PDF, etc.). We have 3 file system sources among our 25 total sources. The remaining 22 sources are all TABLE or DATABASE sources. The DBA here has done a great job getting the data standardized using the typical/default Oracle DATE type format in our TABLE sources (DD-MON-YY). Our tables have anywhere from 1500 rows to 2 million rows.
I tested your theory that the dates we are entering are being changed to Strings behind the scenes and on the Advanced Page, searched for results using OBSDATE equals 01/02/2007 in an attempt to find data that I know for certain to be in the mapped OBSDATE table column as 01-FEB-07. My result set contained data that had an OBSDATE of 03-MAR-07 and none containing 01-FEB-07.
Here is the big issue...in order for my client to fulfill his primary mission, one of the top 5 requirements is that he/she be able to find specific table rows that are contain a specific date or range of dates.
thanks very much! -
All months in date range plus running count
Oracle 11g
Hello all,
Having trouble getting the following query to return proper results. Have a table with a MEMBERNO, BUSINESS_LINE, ELIGIBILITY_START_DATE, ELIGIBILITY_END_DATE.
MEMBERNO is not unique
BUSINESS_LINE is not either
Start and end date are periods of time where: MEMBERNO&BUSINESS_LINE have changed
I need to list the member number, business_line, and each month that falls within the date range beginning with eligibility_start_date & eligibility_end_date, as well as a running count of the total in that span.
Eg.
member, business_line, month, year, count
1234, bus1, 01, 2001, 1
1234, bus1, 02, 2001, 2
1234, bus1, 03, 2001, 3
Here is my SQL, it is not sequencing the months dates correctly and I can not figure out why. Any help is very appreciated:
SELECT memberno,
business_line,
TO_CHAR (ADD_MONTHS (start_date, LEVEL - 1), 'MM') as MONTH,
TO_CHAR (ADD_MONTHS (start_date, LEVEL - 1), 'YYYY') as YEAR,
ROW_NUMBER () OVER (PARTITION BY key1 ORDER BY start_date ASC) as MEMBER_MONTH_COUNT
FROM (SELECT memberno,
business_line,
eligibility_start_date as start_date,
eligibility_end_date as end_date,
member_nbr || business_line as key1
FROM eligibility)
CONNECT BY LEVEL <=
MONTHS_BETWEEN (TRUNC (END_DATE, 'MM'),
TRUNC (START_date, 'MM'))
+ 1;
Edited by: 935047 on Jul 25, 2012 5:58 AM
Edited by: 935047 on Jul 25, 2012 6:18 AM935047 wrote:
I need to list the member number, business_line, and each month that falls within the date range beginning with eligibility_start_date & eligibility_end_date, as well as a running count of the total in that span.
Eg.
member, business_line, month, year, count
1234, bus1, 01, 2001, 1
1234, bus1, 02, 2001, 2
1234, bus1, 03, 2001, 3I could not understand what the Running Count mean. Hence, I used Row_Number (Same as you did).
Below query might match yours.
with data (memb_no, bus_line, st_date, end_date) as
select 1234, 'bus1', to_date('01-01-2001', 'MM-DD-YYYY'), to_date('06-30-2001', 'MM-DD-YYYY') from dual
union all
select 1234, 'bus1', to_date('07-01-2001', 'MM-DD-YYYY'), to_date('07-30-2002', 'MM-DD-YYYY') from dual
min_max as
select memb_no, bus_line, min(st_date) st_date, max(end_date) end_date
from data
group by memb_no, bus_line
lvl as
select level l
from dual
connect by level <= (select max(round(months_between(end_date, st_date))) from min_max)
select memb_no,
bus_line,
to_char(add_months(st_date, l - 1), 'MM') months,
to_char(add_months(st_date, l - 1), 'YYYY') Year,
row_number() over (partition by memb_no, bus_line order by st_date) cnt
from min_max cross join lvl
order by year, months;
----OUTPUT------------------------
MEMB_NO BUS_LINE MONTHS YEAR CNT
1234 bus1 01 2001 1
1234 bus1 02 2001 19
1234 bus1 03 2001 3
1234 bus1 04 2001 4
1234 bus1 05 2001 5
1234 bus1 06 2001 6
1234 bus1 07 2001 7
1234 bus1 08 2001 8
1234 bus1 09 2001 9
1234 bus1 10 2001 10
1234 bus1 11 2001 11
1234 bus1 12 2001 12
1234 bus1 01 2002 13
1234 bus1 02 2002 14
1234 bus1 03 2002 15
1234 bus1 04 2002 16
1234 bus1 05 2002 17
1234 bus1 06 2002 18
1234 bus1 07 2002 2
19 rows selected -
Left outer join using date range returns too many rows
I am trying to pull data for a website.
Names table:
company_name varchar2(30)
julian_day varchar2(3)
logins number(3)
login_errors number(3)
Given a julian date range (e.g. 250-252), I am displaying the information from the Names table.
The problem is that I also need to display changes (increases/decreases) in the data. I do that by coloring the text based on a 10% increase/decrease. Data for the 3 days 250-252 would be compared to data for the previous 3 days 247-249.
Not all companies will report data on all days, so some gaps in the data may exist. Therefore, I cannot do just a simple join.
I am trying to write a query that will give me this information if the user chooses days 250-252.
Company_name
sum(logins) for days 250-252
sum(login_errors) for days 250-252
sum(logins) for days 247-249
sum(login_errors) for days 247-249
The query I'm using is:
select cur.company_name, sum(cur.logins),
sum(cur.login_errors), sum(old.logins), sum(old.login_errors)
FROM names cur LEFT OUTER JOIN names old
ON cur.company_name = old.company_name
WHERE cur.adate>='250' and cur.adate<='252'
and old.adate>='247' and old.adate<='249'
GROUP by cur.company_name
Given this data:
Company_name adate logins login_errors
ABC 247 10 10
ABC 248 20 20
ABC 249 30 30
ABC 250 15 15
ABC 251 25 25
ABC 252 35 35
My problem is that it returns:
adate cur.logins cur.login_err old.logins old.login_err
250 15 15 60 60
251 25 25 60 60
252 35 35 60 60
How can I get it to only give me the one "old" day's data? I went with the LEFT OUTER JOIN because it's possible that there is no data for an "old" day.
Thanks in advance.....Your problem stems from the join itself, and would be the same even without the OUTER JOIN. With your data, there are 3 records in cur and 3 records in old. The join matches each record in cur to each record in old resulting in 9 records in total. Without the SUM, this is clear:
SQL> SELECT cur.company_name, cur.logins, cur.login_errors,
2 old.logins, old.login_errors, cur.adate cad, old.adate oad
3 FROM names cur LEFT OUTER JOIN names old
4 ON cur.company_name = old.company_name
5 WHERE cur.adate>=250 and cur.adate<=252 and
6 old.adate>=247 and old.adate<=249;
COMPANY_NA LOGINS LOGIN_ERRORS LOGINS LOGIN_ERRORS CAD OAD
ABC 35 35 10 10 252 247
ABC 25 25 10 10 251 247
ABC 15 15 10 10 250 247
ABC 35 35 20 20 252 248
ABC 25 25 20 20 251 248
ABC 15 15 20 20 250 248
ABC 35 35 30 30 252 249
ABC 25 25 30 30 251 249
ABC 15 15 30 30 250 249
9 rows selected.You can do this with only one reference to the table.
SELECT company_name,
SUM(CASE WHEN adate BETWEEN 250 and 252 THEN logins ELSE 0 END) curlog,
SUM(CASE WHEN adate BETWEEN 250 and 252 THEN login_errors ELSE 0 END) curerr,
SUM(CASE WHEN adate BETWEEN 247 and 249 THEN logins ELSE 0 END) oldlog,
SUM(CASE WHEN adate BETWEEN 247 and 249 THEN login_errors ELSE 0 END) olderr
FROM names
WHERE adate BETWEEN 247 and 252
GROUP BY company_nameHTH
John -
Query for aggregates for each date in a date range
Hi,
I want to generate a Trend report with a T-SQL proc, which needs following logic.
Input -
Date Range say '10/10/12' to '20/10/12' (Say to check the trend of Size of account in 20 days of Trend report)
Account balance is captured randomly, (i mean not every day)
Table with date looks like this..
--Account Balance Table
CREATE TABLE AccBanalce (
BranchId SMALLINT
NOT NULL,
AccId CHAR(9)
NOT NULL,
Amount DECIMAL(9,3)
NOT NULL,
SnapShotDate DATETIME
NOT NULL
CONSTRAINT PK_AccBanalce PRIMARY KEY NONCLUSTERED (AccId, SnapShotDate) )
GO
Create CLUSTERED INDEX CIx_AccBanalce ON AccBanalce (SnapShotDate)
GO
--Date Range table
CREATE TABLE DateRange ( StartDate DATETIME, EndDate DATETIME)
GO
--Date for the Account Balance Table
INSERT INTO AccBanalce (BranchId, AccId, Amount, SnapShotDate)
VALUES (1, 'C1-100', 10.4, '10/11/2010' ),
(1, 'G1-110', 20.5, '10/11/2010' ),
(2, 'GC-120', 23.7, '10/11/2010' ),
(2, 'Gk-130', 78.9, '10/13/2010' ),
(3, 'GH-150', 23.5, '10/14/2010'),
(1, 'C1-100', 31.8, '10/16/2010' ),
(1, 'G1-110', 54.8, '10/16/2010' ),
(2, 'GC-120', 99.0, '10/16/2010' ),
(3, 'Gk-130', 110.0, '10/16/2010' ),
(3, 'G5-140', 102.8, '10/16/2010' ),
(2, 'GC-120', 105, '10/18/2010' ),
(2, 'Gk-130', 56.7, '10/18/2010' ),
(1, 'C1-100', 84.3, '10/18/2010' ),
(1, 'G1-110', 75.2, '10/19/2010' ),
(2, 'GC-120', 64.9, '10/20/2010' ),
(3, 'GH-150', 84.0, '10/20/2010' ),
(1, 'C1-100', 78.0, '10/20/2010' ),
(1, 'G1-110', 89.5, '10/20/2010' )
GO
--Date for DateRange Table
INSERT INTO DateRange (StartDate, EndDate) VALUES
('2010-10-11 00:00:00.000', '2010-10-11 23:59:59.997'),
('2010-10-12 00:00:00.000', '2010-10-12 23:59:59.997'),
('2010-10-13 00:00:00.000', '2010-10-13 23:59:59.997'),
('2010-10-14 00:00:00.000', '2010-10-14 23:59:59.997'),
('2010-10-15 00:00:00.000', '2010-10-15 23:59:59.997'),
('2010-10-16 00:00:00.000', '2010-10-16 23:59:59.997'),
('2010-10-17 00:00:00.000', '2010-10-17 23:59:59.997'),
('2010-10-18 00:00:00.000', '2010-10-18 23:59:59.997'),
('2010-10-19 00:00:00.000', '2010-10-19 23:59:59.997'),
('2010-10-20 00:00:00.000', '2010-10-20 23:59:59.997')
GO
Question -
I want TOTAL Balance of all Accounts in a Branch per each day between 10/11/2010 to 10/20/2010
If the Snapshotdate (date) on which the account was not made an entery to AccBalance table, last available balance to be considered for that account.
like for account [C1-100] on 10/15/2010 the balance should be [10.4]
--Group By Branch
--Last valid Account balance to be considered.
I know, this is long solution, but any one who is expert in T-SQL can help me in this solution.
Thanks,
KrishnaThanks Himanshu You almost solved my issue...but can you provide the final output as following...
Actually you are aggregating the Amount, which is not required, as it is the total available in that account.
But the missing pint is I need the SUM of all the accounts for each DAY in a BRANCH.
The 3rd Result Query modified to get DAILY balances for each account as following...
--*RESULT*
SELECT a.AccId, a.StartDate,
(SELECT TOP 1 b.Amount
FROM #InterimOutput b
WHERE b.AccId = a.AccId and b.Amount > 0
AND B.StartDate<=A.StartDate ORDER BY B.StartDate DESC) as ToDateBal
FROM #InterimOutput a
ORDER BY a.AccId
go
Now I need SUM of all Account Balances AT each BRANCH on DAILY basics. Can you help on that?
Thanks again
Krishna
Maybe you are looking for
-
EP Login Page is not getting displayed
HI I modified the ume.login.guest_user.uniqueids to add some of the annonymous users to the portal using Direct edit of the UM configuration. I have also changed the index.html file to redirect the anonymopus logon page by changeing the <drive>:\us
-
Creative Cloud desktop app opens but is blank.
Creative Cloud desktop app opens but is blank. Here's what I see.. Nothing shows up. Tried to uninstall, with intention of reinstalling but when I used the uninstaller a popup notice says that it is uninstalled but with errors. No more detailed info
-
My iMac is running slow. When searching in safari it freezes and I have to shut it down several times before it will search. Apps are running slow. What can I do to fix?
-
Factory reset ipad from the "cannot activate" screen in iTunes?
I recently had btea ios6 on the ipad and upgraded it to the full version from the dev account, by downloading the ipsw file, and installing onto laptop. All went well. Anyway, now i'm stuck on the activation screen on the ipad and also in itunes. (so
-
im using the kernel26 from the stable repos, the same for initscipts. But the black background when im using the tty is really boring, there's some way to put some image in the without using some kind of hack?