对于具有相同 orderDate 的订单,我试图在两列中显示订单表中 orderNumber 列的结果。在表中,我有以下数据:
OrderNumber OrderDate
------------ ----------
1 2013-06-01
2 2013-06-02
3 2013-06-03
4 2013-07-05
5 2013-07-09
6 2013-07-09
7 2013-07-15
8 2013-07-15
我需要在两列中显示具有相同 orderDate 且不重复的 orderNumber。我用过这个查询:
SELECT O1.OrderNumber, O2.OrderNumber, O1.OrderDate FROM Orders O1, Orders O2
WHERE O1.OrderNumber <> O2.OrderNumber AND O1.OrderDate = O2.OrderDate
我得到以下结果:
OrderNumber OrderNumber OrderDate
----------- ----------- ---------
3 2 2013-06-02
2 3 2013-06-02
6 5 2013-07-09
5 6 2013-07-09
8 7 2013-07-15
7 8 2013-07-15
this shows that the second line is a duplicate of the first, the fourth the duplicate of the third and the so on.
I want to only keep half of the results
OrderNumber OrderNumber OrderDate
----------- ----------- ---------
3 2 2013-06-02
6 5 2013-07-09
8 7 2013-07-15
或者
OrderNumber OrderNumber OrderDate
----------- ----------- ---------
2 3 2013-06-02
5 6 2013-07-09
7 8 2013-07-15
知道我做错了什么吗?
谢谢。
米萨尔