Home » SQL & PL/SQL » SQL & PL/SQL » Collecting records from 2 tables - please help
Collecting records from 2 tables - please help [message #234] Wed, 30 January 2002 22:56 Go to next message
Fiesel
Messages: 3
Registered: January 2002
Junior Member
Hi,
i hope someone is able to help me.

I have to tables, one containing unique records for item data, the other contains the
moves of the items into and out of the stores.
I need all items which are in store No 1 and quantity is 0 and the last
date of a move is more than 6 months ago, to find items which are no longer in use.

Table1 Store
Item_No
Store_No
Quantity

Table 2 Journal
Item_No
Moving_Date
Store_No

i tried it many different ways now, but it wont work...

select L.item_no, L.quantity from
(select max(J.moving_date) from journal J where (J.store_no = 1)
and (J.moving_date > add_months(sysdate,6))
group by J.item_no), Store L, Journal J
where (L.quantity = 0) and (l.store_no = 1) and (L.item_No = J.item_No);
Re: Collecting records from 2 tables - please help [message #235 is a reply to message #234] Thu, 31 January 2002 02:10 Go to previous message
Mike
Messages: 417
Registered: September 1998
Senior Member
SELECT s.item_no
FROM
(SELECT j.item_no,
MAX(J.moving_date) last_move
FROM journal j
WHERE j.store_no = 1
GROUP BY j.item_no
) l,
store s
WHERE s.quantity = 0
AND s.store_no = 1
AND s.item_No = l.item_No
AND l.last_move < add_months(sysdate,-6);

I guess this is what you want
Mike
Previous Topic: DBMS_SQL.DEFINE_COLUMN problem
Next Topic: Re: ORA 02270
Goto Forum:
  


Current Time: Wed Apr 24 19:21:35 CDT 2024