0

我有一个如下所示的 Oracle 表:

Orders
---------
OrderFullFillID
Description
OrderDate
OrderStatus
Qty

Below are sample records

1    PTS123   1/1/2012     Settled     10
2    PTS123   1/1/2012    ArchSettled  10
3    PTS124   2/1/2012    Settled      10
4    PTS124   2/1/2012    Settled      20
5    PTS125   2/1/2012    Settled      20
6    PTS125   2/1/2012    Settled      20
7    PTS126   2/1/2012    Settled      20
8    PTS126   2/1/2012    ArchSettled  20

如何显示具有相同描述和重复状态='已解决'的记录?将有两条描述相同的记录,statusdate 但不同的状态。我只需要列出 status='Settled' 并且描述相同的那些。

在上面的示例中,查询应返回以下内容:

    3    PTS124   2/1/2012    Settled      10
    4    PTS124   2/1/2012    Settled      20
    5    PTS125   2/1/2012    Settled      20
    6    PTS125   2/1/2012    Settled      20

请帮忙

4

2 回答 2

1
SELECT OrderFulFillID,
       Description,
       OrderData,
       OrderStatus,
       Qty
  FROM orders a
 WHERE status = 'Settled'
   AND NOT EXISTS( SELECT 1
                     FROM orders b
                    WHERE a.description = b.description
                      AND a.statusDate  = b.statusDate
                      AND a.status     != b.status )

应该管用

于 2012-06-19T12:28:48.797 回答
0
SELECT OrderFulFillID,
       Description,
       OrderData,
       OrderStatus,
       Qty
  FROM orders a
  WHERE status = 'Settled'
    AND EXISTS( SELECT 1
                  FROM orders b
                  WHERE a.description     = b.description
                    AND a.OrderFulFillID != b.OrderFulFillID
                    AND a.status          = b.status )
于 2012-06-19T12:44:00.220 回答