473,480 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1743
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
6353
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
5202
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
1581
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
2446
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
1440
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
1344
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
2336
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
1620
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
1670
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
7044
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
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
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7087
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...
1
6741
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
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5341
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
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.