SQL & PL/SQL :: Display All The Months Between Two Dates?

Aug 17, 2010

I have this same problem and still i am getting one error message

ORA-00933: SQL command not properly ended

and the code in highlighted in 'by'

'from test_case partition by'

View 6 Replies


ADVERTISEMENT

All Months Between Two Dates

Sep 17, 2008

I got all the month_numbers when i did this

[/b]select distinct t.f_month_number
from time_dim t
where
f_date between (select start_date from employee where emp_id = 111 ) and
(select add_months(start_Date,12) from employee where emp_id = 111)[b]

but when i add

select distinct t.f_month_number,p.start_date,round(replace(p.total_sal,',','')/12,2) as Monthly_sal
from time_dim t, employee p
where
t.f_date = p.start_date and
f_date between (select start_date from employee where emp_id = 111 ) and
(select add_months(start_Date,12) from employee where emp_id = 111)

i got only one month value.

View 6 Replies View Related

SQL & PL/SQL :: Query To Display Next Ten Dates

Apr 28, 2010

When i had a interview last week they ask me to write a query to display the next ten dates using sql query ( without using PL/SQL).

View 11 Replies View Related

Dates In Sql - Display Name And Next Birthday

Nov 13, 2010

Heres the first question:

Use a select statement with a subquery to display the names of all departments that are responsible for at least one project that has already started.

Heres are the 2 relations:

DEPT(Department table)

COLUMN TYPE SIZE
DEPTNO CHAR 3
DEPTNAME VARCHAR 36

PROJ(Project Table)

COLUMN TYPE SIZE
PROJNAME VARCHAR 24
DEPTNO CHAR 3
STARTDATE DATE

The second question :

For every employee whose birthday falls between now and the end of this year, display the name and next birthday.

Here is the relation:
COLUMN TYPE SIZE
NAME VARCHAR 12
BIRTHDATE DATE

View 3 Replies View Related

SQL & PL/SQL :: Converting Dates - How To Compare Data With Sysdate And Display

Jan 5, 2011

CREATE TABLE SCHEDULE_DETAILS
(
SCHEDULE_ID NUMBER NOT NULL,
SCHEDULE_TYPE VARCHAR2(10 BYTE),
SCHEDULE_START_DATE DATE,
SCHEDULE_END_DATE DATE,
RUNTIME CHAR(8 BYTE),
TIMEZONE VARCHAR2(40 BYTE));

SET DEFINE OFF;
Insert into SCHEDULE_DETAILS
(SCHEDULE_ID, SCHEDULE_TYPE, SCHEDULE_START_DATE, SCHEDULE_END_DATE, RUNTIME, TIMEZONE)
Values
(1970, 'Daily', TO_DATE('07/26/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
TO_DATE('01/26/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), '13:58 ', 'America/New_York');
[code]........

Taking Today date and timezone as EST, I need to run a select that shows all the rows , where sysdate falls in between

Start_date and End_date and RunTime, ( run time is basically the Local time of the TimeZone Column)

Basically we should Display rows by checking/Converting, Start_date||End_date||Runtime||timezone with Sysdate(est) then display.

From the Above Data these rows should be Displayed by that select, how to compare this data with sysdate and display.

SCHEDULE_IDSCHEDULE_TYPESCHEDULE_START_DATESCHEDULE_END_DATERUNTIMETIMEZONE
1970Daily7/26/20101/26/201113:58 America/New_York
2588Daily10/18/20104/18/201115:50 America/New_York
3567Daily12/8/20106/8/20118:40 America/New_York
3386Daily12/27/20106/27/20111:0 America/New_York
1973Daily8/3/20102/3/201111:25 America/New_York
2565Daily9/7/20103/7/20117:0 America/New_York
3580Daily12/20/20106/20/201117:0 America/Chicago
3167Daily11/30/20105/30/20111:0 US/Alaska
3390Daily12/30/20101/15/20117:00 Asia/Calcutta

For Example, Below rows shouldn't come, Since it's end date is less than Sysdate.

SCHEDULE_IDSCHEDULE_TYPESCHEDULE_START_DATESCHEDULE_END_DATERUNTIMETIMEZONE
2579Daily9/17/20109/18/201011:32 America/New_York

View 2 Replies View Related

Finding Individual Dates Having Dates Plus 2 Days

Jan 26, 2011

I want to find the dates which have a date plus with in 2 days after this date. I mean group by 3 days each even the date i missing between two days. Actualy I want to find the start date where the employ was missing on job.

Basic concept is employes have allowed to use 10 personal leaves of a year. Each leave can be use for maximum 3 days.

If employ did not come on the job for one day or two days or three days, it shoul be count as ONE personal leave. And If employ is missing at job for four or five days, it should be count as 2 personal leaves.

seq date
------------------------------
101.01.10

205.01.10
306.01.10

410.01.10
512.01.10

613.01.10
714.01.10
815.01.10

916.01.10
1018.01.10

1119.01.10
1220.01.10
1321.01.10

1423.01.10

1526.01.10
1627.01.10

1729.01.10
1831.01.10

The result should be (Don't use Pl/Sql)

seq date
------------------------------
101.01.10
205.01.10
310.01.10
413.01.10
516.01.10
619.01.10
723.01.10
826.01.10
929.01.10

After finding these days I want to select the starting date of 5th personal leave. (which is 16.01.10).

I am not a expert of using SQL, but I think it could be possible with using partitioning a table on the givin reslult and further partition the reslut on rownum() as rn and the using case statement where rn = 5.

View 2 Replies View Related

SQL & PL/SQL :: Split A Date Into New Dates According To Black Out Dates?

Mar 10, 2011

Split a date into new dates according to black out dates!

Here is my tables:

CREATE TABLE travel
(
start_date,
end_date
)
AS
SELECT DATE '0000-01-01', DATE '9999-12-31' FROM DUAL;

[code]....

I have lets say a "travel date" and black out dates. I will split the travel date into pieces according to the black out dates.

Note: Travel Date can be between 0000-01-01 - 9999 12 31

Sample:

Travel Date:

Travel | START DATE | END DATE
T | 2011 01 04 | 2011 12 11

Black Out Dates:

BO | START DATE | END DATE
A | 2010 11 01 | 2011 02 11
B | 2011 01 20 | 2011 02 15
C | 2011 03 13 | 2011 04 10
D | 2011 03 20 | 2011 06 29

Excepted Result:

New Travel | START DATE | END DATE
X1 | 2011 02 16 | 2011 03 12
X2 | 2011 06 30 | 2011 12 11

Visually:

Travel Date : -----[--------------------------]--

A : --[------]-------------------------
B : ------[---]------------------------
C : --------------[---]----------------
D : ----------------[------]-----------

Result :

X1 : -----------[--]--------------------
X2 : -----------------------[--------]--

Sample 2:

Travel Date : -[--------------------------------]--

BO Date A : ----[------]-------------------------
BO Date B : -------------------------[---]-------
BO Date C : ----------------[---]----------------
BO Date D : ------------------[------]-----------

Result X1 : -[-]-------------------------------
Result X2 : -----------[--]--------------------
Result X3 : -----------------------------[--]--

How can I do it using PL SQL ?

View 5 Replies View Related

Select All Dates Between Two Dates

Oct 22, 2003

How can I select all of the dates between two dates? For example, given the start date 12/2/2003 and the end date 12/5/2003 I want to return:

12/2/2003
12/3/2003
12/4/2003
12/5/2003

Is there a built in function for this? Is there a way for a function to return multiple rows? It has to be a function because I need to use it within other SQL statements.

View 14 Replies View Related

SQL & PL/SQL :: Last 6 Months Data

Jan 5, 2011

I need query to fetch last six months dyanamically based on the mon-yyyy passed by user

Input to query-JUN-2010

Result-
JAN-2010
FEB-2010
MAR-2010
APR-2010
MAY-2010
JUN-2010

View 3 Replies View Related

SQL & PL/SQL :: Months Between Two Date

Apr 28, 2011

I want the months between two date. I want the months like this :

My parameter for the date from and to means i will enter start date and end date

Suppose Date From is 01-apr-11 and end date 31-mar-12

I want the output like this :
April
May
June
July
August
September
October
November
December
January
February
March

How to do this

View 12 Replies View Related

PL/SQL :: How To Get All Months With SQL Query

Aug 8, 2013

I want to display all months (JAN till DEC) in 1st column and their counts in 2nd column but as there are no records in JAN, FEB and march, so they are not coming up.

Get JAN, FEB etc with counts as 0?I know it can be done with NVL function but I don't know where to put it. I'm using oracle 10g on Windows XP. [code]SELECT '',    

CASE      WHEN b.mon= '01' THEN 'JAN' WHEN b.mon= '02' THEN 'FEB' WHEN b.mon= '03' THEN 'MAR'      WHEN b.mon= '04' THEN 'APR' WHEN b.mon= '05' THEN 'MAY' WHEN b.mon= '06' THEN 'JUN'      WHEN b.mon= '07' THEN 'JUL' WHEN b.mon= '08' THEN 'AUG' WHEN b.mon= '09' THEN 'SEP'      WHEN b.mon= '10' THEN 'OCT' WHEN b.mon= '11' THEN 'NOV' WHEN b.mon= '12' THEN 'DEC'    END Months, count(*) cnt  FROM    (SELECT con.fst_name first_name, con.last_name, usr.login USER_ID,        app.appl_src_cd Registration_Source,to_date(usr.created,'DD-MON-YY') Created_Date,      TO_CHAR(usr.created,'MM') mon      from siebel.s_user usr, siebel.s_contact con, siebel.S_PER_PRTNRAPPL app      where con.par_row_id = usr.row_id      and app.row_id = con.row_id      and app.appl_src_cd = 'Siebel eService'    AND TO_CHAR(usr.created,'YYYY') = :P415_YEAR    ) bgroup by b.monorder by 3 desc[/code] 

Right now getting output as....MONTHSCNTAPR4818JUL4543JUN4295MAY4190AUG541MAR20 What Jan, Feb, March etc in it too with count as 0.

View 3 Replies View Related

SQL & PL/SQL :: Printing Months Even Having No Data

Feb 26, 2012

I have table data in which we are entering Visitor's information.We need a monthly report with the count .There are some months which dont have data .So Names of month are not coming .Can i Print Month Name with 0 visitor.

Sample Data

Quote:ID Name Visit_date
1 ABC 01/02/2011
2 DEF 03/04/2011

im using query

Quote:SELECT count(ID) Nos ,TO_CHAR(visit_date,'MONTH') Month FROM DELEGATE_DETAILS WHERE visit_date BETWEEN '01/02/2011' AND '01/04/2011'
GROUP BY TO_CHAR(ARR_DATE,'MONTH')
ORDER BY TO_CHAR(ARR_DATE,'MONTH');
Output
Quote:Nos Month
1 February
1 April

Desired Output:-
Quote:Nos Month
1 February
0 March
1 April

View 2 Replies View Related

SQL & PL/SQL :: Convert Days To Months

Nov 21, 2011

I have the following in my select statement and I am getting the days like 1130, 50, 60 etc

round(MAX (TO_DATE ('31-OCT-2011 23:59:59','dd-mon-yyyy hh24:mi:ss') - a.tx_dtime),0) DAYS

Now I want this to convert these days into months like
1.10 this denotes (one month 10 days)
1.25 this denotes (one month 25 days)
2.05 this denotes (two months 5 days)

I know I am using old Oracle but what to do my company is not spending to upgrade.

View 6 Replies View Related

SQL & PL/SQL :: Merge Number Of Months?

Sep 4, 2012

I need to calculate total number of months within a year that account existed for each SSN.

SSN CODE RECORD_DATE PAYMENT
--- ---- ----------- ----------------------
AAA 00 01-FEB-89 50
AAA 01 01-AUG-89 50
BBB 00 01-FEB-89 0
BBB 01 01-AUG-89 50
CCC 00 01-FEB-89 50
CCC 01 01-AUG-89 0

A non-zero payment indicates that the account was open on that date. A zero payment indicates that the account is closed and assumes that it was open since Jan-01.

AAA: code 00 was open in February, so it was open for 11 months (Feb-Dec)
code 01 was open in August, so it was open for 5 months (Aug-Dec)
So the result should be 11

BBB: 00 - closed in February, existed for 1 month
01 - open in August, existed for 5 months
Result should be 6.

CCC: 00 - 11 months(Feb to Dec)
01 - 7 months (Jan to Aug)
Result: 12 months

Need to get:
AAA 11
BBB 6
CCC 12

Here is the source table:

SELECT 'AAA' SSN, '00' CODE, '01-FEB-89' RECORD_DATE, 50 Payment from dual union all
SELECT 'AAA' SSN, '01' CODE, '01-AUG-89' RECORD_DATE, 50 Payment from dual union all
SELECT 'BBB' SSN, '00' CODE, '01-FEB-89' RECORD_DATE, 0 Payment from dual union all
SELECT 'BBB' SSN, '01' CODE, '01-AUG-89' RECORD_DATE, 50 Payment from dual union all
SELECT 'CCC' SSN, '00' CODE, '01-FEB-89' RECORD_DATE, 50 Payment from dual union all
SELECT 'CCC' SSN, '01' CODE, '01-AUG-89' RECORD_DATE, 0 Payment from dual union all
SELECT 'DDD' SSN, '00' CODE, '01-OCT-89' RECORD_DATE, 0 Payment from dual union all
SELECT 'DDD' SSN, '01' CODE, '01-AUG-89' RECORD_DATE, 50 Payment from dual

View 12 Replies View Related

PL/SQL :: Fetching Date Less Than 3 Months

Sep 12, 2012

How can I fetch a date less than 3 months, if date is '31-Mar-2011' ?

View 3 Replies View Related

SQL & PL/SQL :: Taking Months Off Sysdate?

Feb 25, 2010

I have a table called transaction_dw and I need to select all records that have an account balance that has been below 0 in the past 6 months. initial query I tried was:

select account_balance, timestamp
from transaction_dw
where account_balance < 0
and timestamp between sysdate and sysdate - 6;

but this is only taking 6 days off the sysdate rather than months, how I can get it to take off 6 months?

View 3 Replies View Related

PL/SQL :: To Find Months And Days Between 2?

Oct 9, 2013

 I want to find the months and days between 2 dates. For Eg. Date-1 : 25-Aug-2013Date-2 : 23-Oct-2013 If we consider every month as 30 days it should give 25-Aug-2013 to 30-Aug-2013 = 6 days 01-Sep-2013 to 30-Sep-2013 = 1 Month 23-Oct-2013 to 30-Oct-2013 =   8 days Total = 1 month and 14 days

View 33 Replies View Related

PL/SQL :: How To Get Min Date Of Every Month For Six Months

Mar 25, 2013

I have data like this.

Process_date SEQ_No
------------- ---------
16-MAR-13     733
09-MAR-13     732
02-MAR-13     731
24-FEB-13     730
16-FEB-13     728
09-FEB-13     727
02-FEB-13     726
26-JAN-13     725
21-JAN-13     724
12-JAN-13     723
05-JAN-13     722
29-DEC-12     721
24-DEC-12     720
15-DEC-12     719
08-DEC-12     718
03-DEC-12     717
22-NOV-12     716
17-NOV-12     715
10-NOV-12     714
03-NOV-12     713
29-OCT-12     712
23-OCT-12     711
13-OCT-12     710
05-OCT-12     709
28-SEP-12     708
22-SEP-12     707
15-SEP-12     706
08-SEP-12     705
01-SEP-12     704

every month admin will refresh actual data table and automatically this above table will update with unique seq_no and process_date.

I need to extract min date of every month(First refresh of last 6 months - excluding current month) and also seq_no related to that month so using joins(using seq_no - that is available in main table) i can combine actual data.

I need result like:

02-MAR-13     731 ( I don't need MAR as it should not take current month data)

so i need final result like below:

02-FEB-13     726
05-JAN-13     722
08-DEC-12     718
03-NOV-12     713
05-OCT-12     709
01-SEP-12     704

View 8 Replies View Related

SQL & PL/SQL :: Split Months In Sql Statement

Oct 29, 2012

I need to display the month as below, in a sql statements.

MONTH
JAN-1-15
JAN-16-31
FEB-1-15
FEB-15-28
MAR-1-15
MAR-15-31

i tired with this, but it dint come

select trunc(sysdate, 'year') one, trunc(sysdate, 'year') + floor((last_day(trunc(sysdate, 'year')) + 1 - trunc(sysdate, 'year'))/2) - 1 two,
trunc(sysdate, 'year') + floor((last_day(trunc(sysdate, 'year')) + 1 - trunc(sysdate, 'year'))/2) three, last_day(trunc(sysdate, 'year')) four from dual

View 2 Replies View Related

SQL & PL/SQL :: Pivot Table Comparison Between Months

Jun 28, 2010

SQL> select * from query;

CUSTO SWITCH DATE_X METRIC COUNT_X SEQUENCE_NO FILE
------- ------- --------- ------- ---------- ----------- ----
JCI S1 28-JUN-10 PORT1 10 4 TNB
JCI S1 28-JUN-10 PORT2 4 4 TNB
JCI S1 28-JUN-10 PORT3 8 4 TNB
JCI S2 28-JUN-10 PORT1 1 2 TNB
JCI S2 28-JUN-10 PORT2 5 2 TNB
JCI S3 28-JUN-10 PORT1 6 8 TNB
JCI S5 28-JUN-10 PORT2 2 4 TNB

------->s5 only in the current month-it was not in the previous month data collection
-----------------------------------------------------------------------------
JCI S1 28-MAY-10 PORT1 10 3 TNB
JCI S1 28-MAY-10 PORT3 5 3 TNB
JCI S2 28-MAY-10 PORT1 4 1 TNB
JCI S2 28-MAY-10 PORT2 2 1 TNB
JCI S2 28-MAY-10 PORT3 8 1 TNB
JCI S3 28-MAY-10 PORT2 7 7 TNB
JCI S3 28-MAY-10 PORT3 5 7 TNB
JCI S4 28-MAY-10 PORT1 2 10 TNB
------->s4 in the previous month data

15 rows selected.

1 SELECT A.CUSTO,A.SWITCH,
2 A.PORT1-B.PORT1,
3 A.PORT2-B.PORT2,
4 A.PORT3-B.PORT3
5 FROM (SELECT
6 A.CUSTO

[Code] ......

CUSTO SWITCH A.PORT1-B.PORT1 A.PORT2-B.PORT2 A.PORT3-B.PORT3
------- ------- --------------- --------------- ---------------
JCI S1 0 4 3
JCI S2 -3 3 -8
JCI S3 6 -7 -5

How to include the Switch S4 and S5 in the output. how implemented FULL OUTER JOIN

View 13 Replies View Related

PL/SQL :: Query To Total Attendance By Months

Jul 21, 2012

I need the following totals for each student based on the schools that they are enrolled for each month July through June.

Total Days Suspended from each school

Attendance Table Columns - Absent Date, Absent Code, Pupil_Number, School (Absent Codes for suspended = 3)

Total Days Present at each school - Days Enrolled at each school minus Days Suspended minus Absences

Totals Takes the first day that a student is enrolled (counts the days that the school is in session and the student is not marked absent) Student must be enrolled during the time frame for that month.

Total Days Absent - Total days absent minus suspensions

Examples
Student enrolls in school 11111 on 7/15/2011
Student withdraws from School 11111 on 11/15/2011
Student enrolls in school 22222 on 11/20/2011

Total Days Present should be totaled for each student for each month that they are in a school.

I need 1 row of data for the above student for each month that contains total days suspended, total days present and total days absent.
Pupil Number School Month Totals Days Suspended Total Days Absent Total Days Present

1234 11111 07 0 0 0
1234 11111 08 0 0 4 (school days 4)
1234 11111 09 3 1 16 (schools days 20 - 3-1)
1234 11111 10 0 1 18 (school days 19 - 1)
1234 11111 11 1 1 7 (student enrolled at school A 9 days -1-1)
1234 22222 11 0 1 10 (student enrolled at school B 11 days -1)
1234 22222 12 1 2 17 (school B 20-1-2)
1234 22222 01 0 0 20

View 2 Replies View Related

SQL & PL/SQL :: Number Of Months The Contract Was Open

Aug 21, 2012

I have a contract that has several categories with payments in each one. If there is a payment=0, then a category is considered closed. The contract is considered closed when all categories are closed.

Date Category Payments
01/01/07 1 5
01/01/07 2 7.5
01/01/07 3 6
05/01/07 2 0
09/01/07 1 0
11/01/07 3 0

(date here is in mm/dd/yy)

I need a SQL that will return the number of months within the year that contract was open. In the example above, the last category closed on 11/01, so the result should be 10. If the last line was not there, the contract would still be open in 2007 and the result should be 12.

View 33 Replies View Related

PL/SQL :: Making Sql To Only Return Last 12 Months From Date?

Apr 21, 2013

i have written an sql to look as sales orders but i want it to only return the last 12 months worth of sales for the date its run, the date file [sdtrdj] is julian date so i used to_char to conver it to dd-mm-yyyy how can i get it to only return the last 12 months from the date its run

select
sdshan As "Location", sddcto As "Order Type", sddoco As "Order Number",sdlitm As "Product Code", sddsc1 As "Product Description",
to_char(to_date(sdtrdj + 1900000, 'yyyyddd'),'DD-MM-YY')As "Order Date", sduorg As "Order Qty", sdaexp As "Extended Amount", sdsoqs As "Quantity Shipped",
ibsrp4 As "Srp4", ibsrp6 As "Srp6", ibsrp7 As "srp7", ibsrp9 As "Srp9", ibsrp0 As "srp10", sdsrp2 As "Franchise"
From proddta.f4211, proddta.f4102
Where sdmcu = ' UKC001'
and sddcto = 'KO'
and sdlitm = iblitm and sdmcu = ibmcu
and sdsrp2 In ('504','973','322','236','232','856','233','566','590','470','343','266','279')

View 3 Replies View Related

PL/SQL :: Convert A Number To Years And Months

Jul 30, 2012

I would like to convert a number to years & months.

e.g. 119 = 9 years and 11 months

This would be displayed as 9.11

Is there an oracle function or sql that can calculate this value,

View 8 Replies View Related

Write Simple Sql Which Would Delete Data From Last N Months?

Apr 20, 2009

am trying to write a simple sql which would delete data from last n months but it will keep the data for the first of each of those month from current sysdate

e.g

Jan 1 - 30 deletes 2 - 30 keeps data for 1st
Feb 1 - 28 deletes 2 - 28 keeps data for 1st
Mar
Apr Current sysdate
May

View 3 Replies View Related

SQL & PL/SQL :: Date - How To Get Past 12 Months From Current Month

Dec 17, 2011

I need to get the past 12 months from the current month

for example

input:

march2010

output:

apr2009
may2009
june2009
july2009
augest2009
september2009
october2009
november2009
december2009
january2010
february2010

View 23 Replies View Related

SQL & PL/SQL :: List Persons Having Event In Consecutive Months?

Apr 7, 2011

how to query a list to see if a person had events in consectutive months within the past year. We call a person a LongTermResident if they had a review in any two consectutive months within a reporting period. I wrote a function isResidentLongTerm, passing in FacilityID, ResidentID, ReportPeriodStart, and ReportPeriodStop and returning a 'Y' or 'N'. It works, but the performance is slow.

So if I have a list of reviewers, facilities, reviewees I want to select only those SNF/NF residents who have had routine reviews in any two consectutive months at the same facility.

This is my query:

select ConsultantID, ResidentID
from (
select distinct ConsultantID, FacilityID, ResidentID
from Reviews
where BedType = 17820 -- SNF/NF bed
and ReviewType = 17474 -- routine review
)
where isResidentLongTerm( FacilityID, ResidentID, :startDate, :stopDate ) = 'Y'

View 1 Replies View Related

PL/SQL :: Yearly Quantity Distributed Evenly Across 12 Months

Aug 15, 2012

getting the yearly qty distributed evenly across 12 months. I can do this in PL/SQL but want to know is it possible in SQL.

Database version 10g

create table test_tbl( qty number(22),
yr number,
key_val varchar(10)
);

insert into test_tbl values( 500000, 2013, '1');
insert into test_tbl values (56789, 2014, '2');

commit;

This is the output I need to get from a SQL select query

Key     Month     Year     qty
--------------------------------------------------------------
1     1     2013     41667
1     2     2013     41667
1     3     2013     41667
1     4     2013     41667
1     5     2013     41667
1     6     2013     41667
1     7     2013     41667
[code]....

View 4 Replies View Related

SQL & PL/SQL :: Procedure To Compute Ratios Across Variable Number Of Months

Nov 19, 2011

the problem below:

I have a table AlertData below:

DeptIDMONTHCount
192010-041392
192010-051134
192010-061094
192010-071333
292010-042217

[Code]...

Within each DeptID group I need to calculate absolute change of 'Count' column between previous and current months and compare change value with threshold.

If ratio >= threshold N number of times I need to make a note of that event. Threshold = 0.1 N = 2 - alert needs to exceed threshold two consequtive times

Here is data processing algorithm:

1. Calculate change between month 2010-04 and 2010-05: abs((1134/1392 - 1))= 0.18;
2. check change value against threshold: 0.18 > 0.1
3. Threshold was exceeded, set alert_fired_cnt counter to = 1
4. Once alert fired it creates a baseline for comparison - I need to use Count from month 2010-04: We're now in month 2010-06: abs(1094 / 1392 - 1)=0.21
5. check change value against threshold: 0.21 > 0.1
6. Threshold was exceeded, increment alert_fired_cnt counter by 1 = 2
7. At this point alert exceede threshold two times, I need to set a alert_triggered flag = 1 and reset alert_fired_cnt = 0 for further calculations
8. We're in montn 2010-07: abs(1333/1294-1)=0.03
8. check change value against threshold: 0.03 < 0.1
9. Since threshold was not exceeded, keep alert_fired_cnt counter to = 0

Above algorithm needs to be run for all DeptID groups.

I load above data into an associative array and loop through elements. I am having trouble keeping computations within each DeptID group.

View 18 Replies View Related

SQL & PL/SQL :: Create Select Query That Will Get Data From 18 Months Ago Based On Sysdate?

Sep 9, 2013

I have a table with columns job_id, jan, feb, mar ... , and year

I need to create a select query that will get the data from 18 months ago based on sysdate.

So something like:

Select to_char(add_months(sysdate, -18),'MON') from table1 where job_id = 56947 and year = to_char(add_months(sysdate, -18),'YYYY');

However I need the result of to_char(add_months(sysdate, -18),'MON') to actually act as a column name, not a string result.

View 23 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved