1
我的工作鍛鍊16從sql-ex.ru的組合重複值。這個問題問以下內容:SQL不包括2列
Find the pairs of PC models having identical speeds and RAM.
As a result, each resulting pair is shown only once, i.e. (i, j) but not (j, i).
Result set: model with higher number, model with lower number, speed, and RAM.
數據庫模式是:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
我寫了下面的查詢:
SELECT A.model, B.model, A.speed, A.ram
FROM PC A
JOIN PC B ON (A.model<>B.model)
WHERE A.speed=B.speed
AND A.ram=B.ram
但這顯示我的副本,J爲J,I 。這是我的輸出:
model model speed ram
1121 1233 750 128
1232 1233 500 64
1232 1260 500 32
1233 1121 750 128
1233 1232 500 64
1260 1232 500 32
正如您所看到的,i,j的值被翻轉並計數爲不同的值。有沒有簡單的方法來擺脫這樣的重複?我有點失落。
這是有道理的。沒有考慮對稱價值。 – Paul 2013-04-08 21:20:17