Home » RDBMS Server » Server Administration » query not yet solved
query not yet solved [message #374609] Thu, 21 June 2001 02:09 Go to next message
debasish
Messages: 14
Registered: January 2001
Junior Member
Sorry sandeep, query is not solved.
I am having this order table:
ORDER_NO SC QTY_SUPPLIED O_DATE PC SUPPLY_DA
--------- -- ------------ --------- -- ---------
1 S1 300 12-JAN-97 P1 12-JAN-97
2 S1 200 12-JAN-97 P2 14-JAN-97
3 S1 400 15-JAN-97 P3 25-JAN-97
4 S1 200 18-FEB-97 P4 18-FEB-97
5 S1 100 22-MAR-97 P5 23-MAR-97
6 S1 100 25-MAR-97 P6 25-MAR-97
7 S2 300 28-MAY-97 P1 02-JUN-97
8 S2 400 23-JUN-97 P2 23-JUN-97
9 S3 200 23-OCT-97 P2 23-OCT-97
10 S4 200 14-NOV-97 P2 14-NOV-97
11 S4 300 18-DEC-97 P4
12 S4 400 18-JAN-98 P5 30-JAN-98
13 S5 300 18-FEB-98 P6
My query is
I want all the suppliers who r supplying all the parts supplied by scode='S2'
Re: query not yet solved [message #374610 is a reply to message #374609] Thu, 21 June 2001 03:54 Go to previous messageGo to next message
Hans
Messages: 42
Registered: September 2000
Member
My solution

 
drop table orders;
create table orders (
   order_no          number(10),
   sc                varchar2(5),
   qty_supplied      number(5),
   o_date            date,
   pc                varchar2(5),
   supply_date       date
);
 
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (1, 'S1', 300, to_date('12-JAN-1997','DD-MON-YYYY'), 'P1', to_date('12-JAN-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (2, 'S1', 200, to_date('12-JAN-1997','DD-MON-YYYY'), 'P2', to_date('14-JAN-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (3, 'S1', 400, to_date('15-JAN-1997','DD-MON-YYYY'), 'P3', to_date('25-JAN-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (4, 'S1', 200, to_date('18-FEB-1997','DD-MON-YYYY'), 'P4', to_date('18-FEB-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (5, 'S1', 100, to_date('22-MAR-1997','DD-MON-YYYY'), 'P5', to_date('23-MAR-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (6, 'S1', 100, to_date('25-MAR-1997','DD-MON-YYYY'), 'P6', to_date('25-MAR-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (7, 'S2', 300, to_date('28-MAY-1997','DD-MON-YYYY'), 'P1', to_date('02-JUN-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (8, 'S2', 400, to_date('23-JUN-1997','DD-MON-YYYY'), 'P2', to_date('23-JUN-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (9, 'S3', 200, to_date('23-OCT-1997','DD-MON-YYYY'), 'P2', to_date('23-OCT-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (10, 'S4', 200, to_date('14-NOV-1997','DD-MON-YYYY'), 'P2', to_date('14-NOV-1997','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (11, 'S4', 300, to_date('18-DEC-1997','DD-MON-YYYY'), 'P4', null );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (12, 'S4', 400, to_date('18-JAN-1998','DD-MON-YYYY'), 'P5', to_date('30-JAN-1998','DD-MON-YYYY') );
insert into orders ( order_no, sc, qty_supplied, o_date, pc, supply_date)
   values (13, 'S5', 300, to_date('18-FEB-1998','DD-MON-YYYY'), 'P6', null );
commit;
 
 
-- <b>Interpretation 1:</b>
-- all suppliers without 'S2' who delivers part 'P1' and 'P2' and more
select distinct a.sc from orders a
   where a.sc != 'S2'
   and not exists
      (  
         select pc from orders b
            where sc = 'S2'
         minus
         select pc from orders b
            where b.sc = a.sc
      );
 
-- <b>Interpretation 2:</b>
-- all suppliers without 'S2' who delivers exactly part 'P1' and 'P2'
select distinct a.sc from orders a
   where a.sc != 'S2'
   and not exists
      (  
         select pc from orders b
            where sc = 'S2'
         minus
         select pc from orders b
            where b.sc = a.sc
      )
   and not exists
      (  
         select pc from orders b
            where b.sc = a.sc
         minus
         select pc from orders b
            where sc = 'S2'
      );
      
   
Re: query not yet solved [message #374630 is a reply to message #374609] Fri, 22 June 2001 00:32 Go to previous message
Sudhakar Atmakuru
Messages: 58
Registered: May 2001
Member
Try this out:

SELECT SC FROM ORDER_TABLE WHERE PC IN (SELECT PC FROM ORDER_TABLE WHERE SC='S2');

First the subquery filters out what are the parts supplied by S2 and then the main query checks whether the product supplied by a supplier is in that filtered list. Hope this resolves your problem.
Previous Topic: query not yet solved
Next Topic: updating fields?
Goto Forum:
  


Current Time: Sat Jul 06 08:30:37 CDT 2024