Home » RDBMS Server » Server Administration » Problem creating a query
Problem creating a query [message #372002] Wed, 03 January 2001 07:51 Go to next message
Raphael
Messages: 2
Registered: January 2001
Junior Member
Hi Freinds

I have a problem in creating a query. Following is the table on which the query is to be build.

Client_Id Booking_Date Quantity
1 25-OCT-2000 10
2 10-OCT-2000 20
3 12-OCT-2000 60
1 01-OCT-2000 40
3 25-OCT-2000 80
2 10-OCT-2000 90
1 15-OCT-2000 50
3 25-OCT-2000 35
2 10-OCT-2000 40
1 30-OCT-2000 30
2 25-OCT-2000 30
3 10-OCT-2000 50
1 18-OCT-2000 20

This table contains transactions done by different clients. Based on this table I have to create a query which returns me the latest 3 transactions done by a particular client ie. for example if i take client_Id 1 then their are five transactions for him which are as follows

Client_Id Booking_Date Quantity
1 25-OCT-2000 10
1 01-OCT-2000 40
1 15-OCT-2000 50
1 30-OCT-2000 30
1 18-OCT-2000 20

Out of these transactions the following transactions should be returned by the query
Client_Id Booking_Date Quantity
1 18-OCT-2000 20
1 25-OCT-2000 10
1 30-OCT-2000 30

The query should be ordered on Booking_Date, that is known to me but how exactly to extract the last three records.

Please help

Thanking You

Raphael
Re: Problem creating a query [message #372003 is a reply to message #372002] Wed, 03 January 2001 08:11 Go to previous message
Bala
Messages: 205
Registered: November 1999
Senior Member
Hi,

select client_Id, booking_date, quandity
from t1 a
where 3 > (select count(*)
from t1 b
where b.booking_date > a.booking_date)
and client_Id= 1;
Previous Topic: I am looking for a sql application to download
Next Topic: PL/SQL Oracle 8i select statemet problem
Goto Forum:
  


Current Time: Fri May 17 22:24:35 CDT 2024