A tough SQL . [message #20097] |
Tue, 30 April 2002 01:50 |
Nikhil
Messages: 5 Registered: April 2002
|
Junior Member |
|
|
I am not able to write a SQL for a query . Please
help me. i have to tables myday and mytran . my day
contains a date and its attributes e.g.
day,month,year. and mytran table contain two coumns
odate(date of order) and sdate(date of sale).
I want to display those records where day of order is
23 and day of sale is 29. According to this question
it should display last two records of mytran table.
Please help me in building the SQL.
I have tried the following sql but it's not working
Plese mail me the result on nikhilsan@yahoo.com
select a.* from mytran a,myday b where
(a.odate=b.dt and a.odate in (select dt from myday
where day=23)) and (a.sdate=b.dt and a.sdate in
(select dt from myday where day=30));
(Structure and data in the tables)
# select * from myday;
dt | day | month | year
------------+-----+-------+------
2002-04-23 | 23 | 4 | 2002
2002-04-24 | 24 | 4 | 2002
2002-04-29 | 29 | 4 | 2002
2002-04-30 | 30 | 4 | 2002
(4 rows)
# select * from mytran;
odate | sdate | id
------------+------------+----
2002-04-29 | 2002-04-30 | 1
2002-04-23 | 2002-04-30 | 1
2002-04-23 | 2002-04-30 | 1
(3 rows)
thanks
|
|
|
Re: A tough SQL . [message #20141 is a reply to message #20097] |
Wed, 01 May 2002 05:03 |
Lakshmi narasimhan
Messages: 2 Registered: May 2002
|
Junior Member |
|
|
please write the following query it will work
Wrote file afiedt.buf
1 select a.* from mytran a,myday b, myday c
2 where
3 (a.odate=b.dt and a.odate in (select dt from myday
4 where day=23)) and (a.sdate=c.dt and a.sdate in
5* (select dt from myday where day=30))
RAPID/rdek>/
ODATE SDATE
--------- ---------
23-APR-02 30-APR-02
23-APR-02 30-APR-02
|
|
|