query with conditions

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
 
K

KARL DEWEY

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

parameter query needed 7
Pls help. urgently required 2
query 1
delete query wth a condition 1
query needed please help 6
Pls help with SQL query 12
query 3
SQL 2

Top