473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Urgent Query

Here is my question:

create table x (t varchar2(10), dt date);

data in the table x( Keep in mind, I actual table it has over 3
million rows, so performance is critical )

t dt
------------- ------------
1001 01/01/2004 10:10:00
1001 01/01/2004 10:11:00
1001 01/01/2004 10:12:00
1001 01/01/2004 10:13:00
1002 01/01/2004 11:10:00
1002 01/01/2004 11:11:00
1002 01/01/2004 11:12:00
1002 01/01/2004 11:13:00

I need to write a query to tell me for each row when was the last
dt/time:
so for 1001 and 1002 i will have one less record:
t dt previous_dt
------------ ----------------- --------------------
1001 01/01/2004 10:11:00 01/01/2004 10:10:00
1001 01/01/2004 10:12:00 01/01/2004 10:11:00
1001 01/01/2004 10:13:00 01/01/2004 10:12:00
1002 01/01/2004 10:11:00 01/01/2004 10:10:00
1002 01/01/2004 10:12:00 01/01/2004 10:11:00
1002 01/01/2004 10:13:00 01/01/2004 10:12:00

Thanks alot
Jul 19 '05 #1
1 1740
VC
Hello,
"Windsurfer" <ns******@yahoo.com> wrote in message
news:14**************************@posting.google.c om...
Here is my question:

create table x (t varchar2(10), dt date);

data in the table x( Keep in mind, I actual table it has over 3
million rows, so performance is critical )

t dt
------------- ------------
1001 01/01/2004 10:10:00
1001 01/01/2004 10:11:00
1001 01/01/2004 10:12:00
1001 01/01/2004 10:13:00
1002 01/01/2004 11:10:00
1002 01/01/2004 11:11:00
1002 01/01/2004 11:12:00
1002 01/01/2004 11:13:00

I need to write a query to tell me for each row when was the last
dt/time:
so for 1001 and 1002 i will have one less record:
t dt previous_dt
------------ ----------------- --------------------
1001 01/01/2004 10:11:00 01/01/2004 10:10:00
1001 01/01/2004 10:12:00 01/01/2004 10:11:00
1001 01/01/2004 10:13:00 01/01/2004 10:12:00
1002 01/01/2004 10:11:00 01/01/2004 10:10:00
1002 01/01/2004 10:12:00 01/01/2004 10:11:00
1002 01/01/2004 10:13:00 01/01/2004 10:12:00

Thanks alot


You cannot do any faster than that -- only one FTS:

select * from
(select t, dt, lag(dt) over (partition by t order by dt) dt_previous from
x)
where dt_previous is not null
Rgds.

VC
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edwinah63 | last post by:
Hi Everyone, All the very best for 2004!! i need urgent help with this problem, the users are about to skin me alive!! we have an access front end with linked to sql server 2k tables. ...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
6
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated...
1
by: AVL | last post by:
Hi I'm working on indexing a website. I want to restict the search to only few file types like .doc,.txt and.ppt How to specify the file types in the 'ixsso.Query' object Presently i'n using...
6
by: sangram_149 | last post by:
hi, i have a query which fetches the sum of amounts from a table .the column is 19 bytes but the query returns only the actual amount..for example ..it returns ... -1245.00 but i want it to...
1
by: Liam.M | last post by:
HEY GUYS, need some urgent help here....I am querying my database based on a DueDate field...and want to send an automated email to anyone that falls within two months PRIOR to this "DueDate",...
2
by: JHNielson | last post by:
I Know I've posted an Urgent message before. But I'm in the middle of system testing, and these little stupid bugs are killing me...... I have a query that checks that a set of values (the...
5
by: gopim | last post by:
strSql = "SELECT ISNULL(max(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users"; sqlCmd.CommandText = strSql; sqlDr = sqlCmd.ExecuteReader(); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.