query with conditions

  • Thread starter Thread starter subs
  • Start date Start date
S

subs

ozip dzip shipdate
101 202 1/12/2009
121 202 1/12/2009
131 12 1/14/2009
11 12 1/14/2009
5 7 1/20/2009
8 7 1/20/2009

I want to extract all records which have same dzip and same shipdate
but different ozips. These records will form groups. Once these groups
are formed, i want to extract only those groups which meets another
condition

In each of the groups, one ozip has to be either 101 or 112 and the
other ozip has to be either 121 or 8.

So in the above example, in the final query result the first group
( i.e first two rows) are only selected. The last four rows form two
groups of two records each but are not selected in the final result
sinc they donot mee the condition of ozips. Pls help with a SQL for
the desired result Thanks
 
SELECT X.*
FROM PPG AS X INNER JOIN PPG AS Y ON (X.Ship_Date=Y.Ship_Date)
WHERE (X.Ozip<>Y.Ozip) AND (X.Dzip=Y.Dzip);
 
Back
Top