PL/SQL :: Selecting Missing Date Range With Previous Records Value

Jun 8, 2012

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - ProductionSET DEFINE OFF;
[code]....

10 rows selected.I want the output like as follows, all those missing date i need to carry on the last one's number

  NBR_OF_S   NBR_OF_C S_DATE
---------- ---------- ---------
        34         40 01-MAY-12
        27         29 01-APR-12
        27         29 01-MAR-12
        21         23 01-FEB-12
        21         23 01-JAN-12
        21         23 01-DEC-11
[code]....
       
The date value I have created for this sample is monthly, based on the condition the data value I may need to generate weekly also. That's Monthly or weekly either one.

View 9 Replies


ADVERTISEMENT

SQL & PL/SQL :: Selecting Specific Date / Time Range?

May 8, 2013

I want to select a specific date/time range in a query. I want to select from 6 AM yesterday through 6 AM today. I know that CURRENT_DATE - 1 will give me yesterday, and I can search between that and the current_date. However, how do I incorporate the specific time in the query?

View 4 Replies View Related

SQL & PL/SQL :: Counting Records Within A Date Range?

Nov 1, 2011

I am trying to write part of an SQL where it gives me a count of bookings in any 6 month period made from the first booking.Example of records

enquirynumberenquiryaddresssubjectcodebookingdate
613651 Burberry AvenueBCHR20/10/2008 07:00:00
613801 Burberry AvenueBCHR20/11/2008 07:00:00693021 Barberry AvenueBCHR07/09/2009 07:00:00

I am so far getting 3 as a count result based on SQL below. I want the count to return 2 (because its inside the 6 month range):

SELECT
ce1.enquirynumber,
ce1.enquiryaddress,
es1.subjectcode,
b1.bookingdate,
(SELECT count(b2.bookingdate)
[code]....

View 2 Replies View Related

SQL & PL/SQL :: Selecting Value Of Previous Column In Case Statement?

Feb 20, 2012

Is there a way of selecting the value of a previous column in a case statement, without having to duplicate. E.g.

SELECT prod_id as Product,
Some complex calculation... as Total,
CASE

[Code]....

I do not want to re-write the same calculation in the else statement but just want it to be be the value of Total column.

View 1 Replies View Related

PL/SQL :: Selecting Certain Day Of Week From Range Of Dates

Nov 21, 2012

I have a table with a count of customers for about a year, but I only want to select Wednesday and Thursday of each week, starting at the beginning of dates. Table is simple and has two columns. Each row is Distinct to a Date, there are no Date duplicates, it's counted for each day of the year.

column 1: count of customers, count(customer_id)
column 2: Date

Not even sure if this is possible to select a date using the day name ?

Basically I want to select each Wednesday and Thursday from each week and compare the counts week over week, over week for all week to see if the counts are going up or down, to get trends .

View 4 Replies View Related

PL/SQL :: Retrieve Date Range From 2 Search Input Date Fields

Aug 16, 2012

I would like to inquire how do I code my select statement if my user enter a search date range(search startDt: 01/08/2012 and search endDt :30/09/2012) and I will like to retrieve only the 7records out from my table as shown below ?

STARTDT_     ENDDT_
01/08/2012 01/08/2012
01/06/2012 31/12/2012
01/08/2012 01/08/2012
01/09/2012 01/09/2012
01/09/2012 31/12/2012
01/07/2012 01/07/2012->not retrieved out
01/08/2012 01/08/2012
01/01/2012 31/12/2012

View 6 Replies View Related

PL/SQL :: Date Difference - Include Both Start And End Date In Range

Aug 8, 2013

select to_date('28-FEB-2013') - TO_DATE('01-FEB-2013')  FROM DUAL 

gives me 27 days, what should I do to get 28 ? meaning include both the start and end dates in the range ?

View 3 Replies View Related

Selecting A Set Of Records From One Table

Aug 19, 2010

I'm selecting a set of records from one table, for example: ID, description and date. From this I'm only wanting the latest inserted row. I've used the max function on the date which is fine, however, there are some records that have had their description changed. This then returns two values for one ID, the max for the original description and the max for the changed description.

I'm getting:

ID |Description |Date
1 ABC 01/01/2010
2 XYZ 02/03/2010
2 XYZ1 03/05/2010

When I want:

ID |Description |Date
1 ABC 01/01/2010
2 XYZ1 03/05/2010

As ID 2 with XYZ1 Description is the very latest row for that ID.

This is an audit table so the ID appears on numerous rows as it a composite key with date.

View 1 Replies View Related

PL/SQL :: Selecting Records Based On The Flag

Jun 7, 2012

I have records like the following

Program_Name Effective_Date Valid_Flag
ABCD 2/10/2012 N
ABCD 2/14/2012 N
ABCD 2/20/2012 Y
ABCD 3/01/2012 N
ABCD 3/10/2012 N

[Code]...

I have to write a select statement to to keep the first record and then pull only the records when the Valid_Flag changed. The result set should be like below.

Program_Name Effective_Date Valid_Flag
ABCD 2/10/2012 N -- I have preserved the first record
ABCD 2/20/2012 Y -- Valid_Flag chages to a Y for teh first time and so on.
ABCD 3/01/2012 N
ABCD 3/14/2012 Y
ABCD 3/25/2012 N
ABCD 4/25/2012 Y

If there is no change in the flag, I do not have to pull that record.

View 3 Replies View Related

PL/SQL :: Selecting Records Based On Value Of Field

Dec 5, 2012

I have a table test with 10,000 records in it and 50 columns.I have to select those rows which contain values as "Sales Dum" in their field..For table with small number of colums i did this

SELECT * FROM tbl_website_dtl WHERE created_by like '%Sales%' or website_name like '%Sales%' or website_code like '%sales%';But should i do for table containing 50 columns.

View 5 Replies View Related

SQL & PL/SQL :: Selecting Latest Date

Aug 23, 2012

have a bit of a SQL trouble. I have a simple table (pcuk_BG_alloc_TAB) which stores Parts, Quantities and Applied dates

PART_NO QUANTITY APPLIED
PartA 100 10/8/2012
PartA 200 12/8/2012
PartB 30 12/8/2012
PartC 50 10/8/2012
PartC 75 15/8/2012
PartC 80 21/8/2012

I am only interested the latest applied date for each part and am looking for this to be returned in a select statement (as below)

PART_NO QUANTITY APPLIED
PartA 200 12/8/2012
PartB 30 12/8/2012
PartC 80 21/8/2012

I have tried using the max function (select part_no, quantity, max(applied) from pcuk_BG_alloc_TAB group by part_no, quantity) but seems as the records have different quantities it treats them separately.

View 21 Replies View Related

SQL & PL/SQL :: Compare Previous Records With Current?

Aug 29, 2013

I am trying to set the min date if there is no gap between dates.compare previous date2 value with current date1,if they are same then my new date will be min(date1).

source data

date1 iddate2 new_date
1/2/20111234/2/2011
4/2/20111237/2/2011
7/2/201112310/2/2011
10/2/20111231/2/2012
1/2/20121234/2/2012
4/2/20121237/2/2012
12/17/20121233/17/2013
3/17/20131236/17/2013

and I am expecting the out put like this

date1 id date2 new_date
1/2/20111234/2/20111/2/2011
4/2/20111237/2/20111/2/2011
7/2/201112310/2/20111/2/2011
10/2/20111231/2/20121/2/2011
1/2/20121234/2/20121/2/2011
4/2/20121237/2/20121/2/2011
12/17/20121233/17/201312/17/2012
3/17/20131236/17/201312/17/2012

how to achieve this with SQL

View 3 Replies View Related

Selecting All Queries Executed Between Given Date And Now

Oct 26, 2010

Is information in v$sql enough to select all queries executed between given date and now? When the queries are removed from v$sql?

View 1 Replies View Related

Selecting Data From Table On Date Criteria

May 27, 2011

I am new to oracle and have an issue with selecting data from a table on date criteria.

select * from table1 t where t.DT BETWEEN TO_DATE(sysdate-1,'dd/mm/yyyy') AND sysdate

my understanding is that this should give me the data for just one day. but it is not.

What I want is, data for last 30days from today.

View 2 Replies View Related

Application Express :: Show Input After Selecting Date In Datepicker?

Jun 11, 2012

I'm using apex 4.1.1 And i want to use a Date Picker item on my page. This works, but.. When a user selects a date you can see the date highlighted. But in the "textarea"corresponding tot the datepicker is not showing the date. This shows the date after clicking the close button.

I would like to show the date directly after selecting a new date.

View 7 Replies View Related

SQL & PL/SQL :: Calculations - Get Same Month From Previous Year Of Selected Date

Sep 20, 2011

i have a requirement to create a query which gets the same month from the previous year of the selected date .

Example : i select SEP-2011 ( as sysdate )

it will return the SEP-2010 as well .

here is the code which works fine with sysdate, dual :

SELECT
TO_CHAR(ADD_MONTHS(SYSDATE,-12),'MON-YYYY') TMLY, TO_CHAR(SYSDATE,'MON-YYYY') TMTY FROM DUAL;

in my schema table Ive got a filed named PERIOD_NAME (varchar2) , which holds date values in ( Mon-YYYY ) format (e.g Sep-2011)

am unable to apply the above code on it , i guess its the data type pf the field .

View 5 Replies View Related

SQL & PL/SQL :: Return Most Recent Record Previous To Start Date?

Nov 18, 2011

I have a sub query (already dervived from several other tables) that has a list of children in with the date they started their course (tableofchildren). Child IDs may be duplicated in this query but each record will have unique start dates per child ID.

I have a second sub query which lists workers involved with the children in the first query (tableofworkers). A worker may be responsible for more than one child but has the unique child in the record to identify involvement with the child.

I need to join these queries together to return the child's record with the WorkerName and the AllocatedStartDate of the worker who was most recently involved with the child prior to the date (EnteredCourseDate) the child started their course (OutputWanted) - the worker associated with the child when they started their course.

A couple of points - I need to deploy this into another reporting application that doesn't support cursors etc or the 'With' operator. Also, I tend to join tables/queries in the Where clause so if it's possible that way that would be great.

OC.
create table tableofchildren
(ChildID varchar(20),
ChildName varchar (50),

[Code].....

View 13 Replies View Related

SQL & PL/SQL :: Generate Records For Range Of Each ID

Sep 13, 2013

write the query for the following requirement.I need to generate the records for the range (Difference between From_val & to_val) ) for each ID

create table test_base(id varchar2(20) , from_val number , to_val number);

insert all
into test_base values ('A', 6,10)
into test_base values ('B', 22,30)
into test_base values ('C', 123,130)
into test_base values ('D', 852,860)
into test_base values ('E', 30 ,30)
select * from dual ;
[code]....

No need to generate any thing for E as the difference is equal to Zero

View 4 Replies View Related

SQL & PL/SQL :: How To Get The Missing Records Using Only One Statement

Jan 1, 2011

Ten thousand (10000) records ,but in the TABLE that has a uniqure sequence of column named seq, find only 9 thousand (9000) records. I want to find out the missing records. The following is my approach, but it is not the best way

1.CREATE TABLE my_public_seq (seq number(10));

2.
DECLARE
vn_seq NUMBER(10);
BEGIN
FOR i IN 1..10000
LOOP
INSERT INTO my_public_seq VALUES(i);
END LOOP;
COMMIT;
END;

3. run sql
SELECT seq FROM my_public_seq
MINUS
SELECT seq FROM my_original_table_that_missing_some_records;

How to get the missing records using only one SQL statement.

View 1 Replies View Related

SQL & PL/SQL :: Range Output And Limit Records

Jun 18, 2012

I need to display the data as range , i have created one table along with inserts as below , i need the desired output as mentioned below.The range will start from field STMH_PM_CODE , it will get the first and last stmh_pm_code and stmh_pm_desc which are in the same combination of STMH_NO,STMH_JOB_NO,STMH_batch_no and stmh_rev_no,

SQL> CREATE TABLE OT_SHOP_TRANSMITTAL_TEST
2 (
3 STMH_NO VARCHAR2(15),
4 STMH_JOB_NO VARCHAR2(12),
5 STMH_BATCH_NO VARCHAR2(12),
6 STMH_PM_CODE VARCHAR2(35),
7 STMH_PM_DESC VARCHAR2(240),
8 STMH_REV_NO VARCHAR2(12)
9 );

Table created.

SQL> INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1001','FRAME','0');

1 row created.

SQL> INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1002',FRAME','0');
ERROR:
ORA-01756: quoted string not properly terminated

SQL> ED
Wrote file afiedt.buf

1* INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1002','FRAME','0')
SQL> /

1 row created.

SQL> INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1003','COLUMN','0');

1 row created.

SQL> INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0002','1107040-1004','FRAME','0');

1 row created.

SQL> INSERT INTO OT_SHOP_TRANSMITTAL_TEST VALUES ('PR-1107-0001','1107040','0001','1107040-1005','FRAME','0');

1 row created.

SQL> COMMIT;

Commit complete.

-- i want it as below see the line in stmh_pm_desc the description gets added until there is a change in either stmh_batch_no or stmh_rev_no since we have stmh_pm_code 1107040-1004 with stmh_batch_no 0002 it goes to other line as a seperate new range and first one will stop with 1107-1003 as that is the last combination and new line or range will get added over again.

STMH_NO STMH_BATCH_NOSTMH_PM_CODE STMH_PM_DESCSTMH_REV_NO
PR-1107-000100011107040-1001 - 1107040-1003FRAME, COLUMN0
PR-1107-000100021107040-1004 FRAME 0
PR-1107-000100011107040-1005 FRAME 0

View 39 Replies View Related

SQL & PL/SQL :: Max (date) And Previous Max (date)

Feb 10, 2010

I would like to select the max(date) in a table and then select the next previous max(date) in the same table and then show both dates with the calculated timespan between them.

So it would look like

max(date) next_previous_max(date) timespan_between

I want the max two dates in the table and the time between the two dates.

View 8 Replies View Related

SQL & PL/SQL :: Report With Date Range

Feb 4, 2013

I have a cost data for effective date range as below.

MODEL_NOTIER_COSTEFFECTIVE_START_DATEEFFECTIVE_END_DATE

I3 3770 265 2/3/2013 3/31/2013
I3 3770 269 4/1/2013 5/4/2013

This data needs to be represented in a SQL report as below. The Date Range in the below i.e., Starts with FEB, by checking against the sysdate.. That is from sysdate it will display the Quarter data for 4 months as below.

MODEL NOFEB FY13MAR FY13APR FY13MAY FY13
I3 3770 265 265 269 269

Currently I am using a procedural logic to populate data into a different table in the above format. Is there any method to do with a single SQL using PIVOT. Below given is the table structure and Insert scripts.

CREATE TABLE ITEM_TAG(MODEL_NO VARCHAR2(50), TIER_COST NUMBER(13,4), EFFECTIVE_START_DATE DATE, EFFECTIVE_END_DATE DATE );

Insert statements

Insert into ADMIN_COSTPL_OWNER.ECAPS_ENTITLEMENT
(MODEL_NO, TIER_COST, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE)
Values
('I3 3770', 265, TO_DATE('02/03/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into ADMIN_COSTPL_OWNER.ECAPS_ENTITLEMENT
(MODEL_NO, TIER_COST, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE)
Values
('I3 3770', 269, TO_DATE('04/01/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('05/04/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;

View 10 Replies View Related

SQL & PL/SQL :: Restriction In Date Range?

May 7, 2012

I want my user to be restricted for entering duplicate time within two times.

create table asd(dt_frm date,dt_to date);

insert into asd VALUES(to_date('01-04-2012 08:00','dd-mm-yyyy hh24:mi'),to_date('01-04-2012 10:00','dd-mm-yyyy hh24:mi'));
insert into asd VALUES(to_date('01-04-2012 09:00','dd-mm-yyyy hh24:mi'),to_date('01-04-2012 11:00','dd-mm-yyyy hh24:mi'));

now in the second insertion I want to alert the entry user that 9am already falls in the saved record which is 8am to 10am and so that this record can't be saved.

View 8 Replies View Related

SQL & PL/SQL :: Generate List Of Records Within Range (two Values)?

Mar 15, 2012

I am using PL/SQL Developer.I have two tables: A and BTable A contains serial_from and serial_to values.This is used to define the serial numbers issued to customers (i.e. the start and end range of serial numbers issued).Shown here for a client:

Table B contains the individual numbers, B.serial (within the serial_from and serial_to range) along with other data, and is only created when the serial is used by the client.

I would like to create a list of records for individual clients containing serial numbers issued but not used. i.e. they are in between the serial_from and serial_to values in Table A, but not in Table B.

How can I create a list of numbers issued, but not yet used? Because Table A contains only two values (to and from) no record exists for them, so how do I generate a list and check against it?

View 3 Replies View Related

Date Range Vs Interval Partitioning

Dec 16, 2010

Other than the obvious to me, where interval partitioning creates partitions as needed. Is there any performance benefit from using interval partitions vs date range partitions.

One draw back for me is that developers do access the partition name in some of their queries, so if I use date range partitioning this will not break their code. I could not find a way to assign a name to a partition when using intervals, is this always system generated or can this be over-ridden.

I am running Oracle 11.1.0.7 soon to be running on 11.2.0.0

View 6 Replies View Related

SQL & PL/SQL :: Display 1st Day Of Week Within Date Range

Jul 14, 2010

How to display date every monday within date range

DEsc start date end date
XXXX 1/2/2010 31/10/2010

output
date every monday

View 25 Replies View Related

SQL & PL/SQL :: Find Years Between Any Given Date Range

Apr 5, 2011

I require to find the years between any given date range. For example what are the years between the dates '01/12/2010' and '01/02/2012'? Answer must be '2010,2011,2012'. how to code the query for this result?

View 2 Replies View Related

SQL & PL/SQL :: Selection Based On Date Range

Dec 16, 2011

Problem:

Our term (strm) is dictated by the term_begin_dt and term_end_dt dates but I want to keep selecting that term until 1 week before the next term opens and then switch to that term.

Basically, I don't want any gaps between a term.

Output:

select strm when sysdate is between term_begin_dt and term_end_dt (strm would equal 3943)
select strm until 1 week before the start of the next term (4027) (strm would equal 3943)
select strm when 1 week before term_begin_dt (strm would equal 4027)

Repeat for the next term and so on 12/16/2011
select strm
from term
where trunc(sysdate) between trunc(term_begin_dt) and trunc(term_end_dt)

Output: 3943
12/17/2011 - 01/01/2012

select strm
from term
where ?

Output: 3943

01/02/2012 - 5/4/2012
select strm
from term
where ?

Output: 4027

Repeat.

Test Case:

CREATE TABLE TERM
(
STRM VARCHAR2(4 BYTE),
DESCR VARCHAR2(20 BYTE),
TERM_BEGIN_DT DATE,
TERM_END_DT DATE
)

Insert into TERM
(STRM, DESCR, TERM_BEGIN_DT, TERM_END_DT)
Values
('3943', '2011 Fall Semester', TO_DATE('08/22/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
TO_DATE('12/16/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TERM
[code].....

View 2 Replies View Related

SQL & PL/SQL :: Count Data Within Date Range?

Nov 15, 2010

I need to know the counts(into buckets) for each event_date for a given event_id.

I have 4 buckets that I'm trying to calculate

1. Past (from Today)
2. Today
3. > Today but within 3 days in the future
4. More than 3 days in the future

WITH event_data AS
(SELECT '1' event_id, SYSDATE - 1 event_date
FROM dual
UNION ALL
SELECT '1' event_id, SYSDATE
FROM dual

[code]....

Sample Output:

EVENT_IDPASTTODAYWITHIN_3_DAY_WINDOWOUTSIDE_3_DAY_WINDOW
1 111 1
2 102 0

View 3 Replies View Related

PL/SQL :: Date Range Sunday To Monday

May 16, 2013

I would like to design a date range query where the beginning of the week is always sunday and the end of the week is always monday.

View 3 Replies View Related







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