我想解決一個SQL演習。尋找PC模型對
這裏的架構
PC
code int
model varchar(50)
speed smallint
ram smallint
hd real
cd varchar(10)
price money
問題:
找到對具有 類似的速度和RAM PC機型。結果, 每個結果對只顯示 一次,即(i,j)但不顯示(j,i)。
我寫了一個查詢,但它顯示(i,j)和(j,i)。
我的查詢:
select t1.model,t2.model,t1.speed,t1.ram from pc t1 , pc t2
where t1.speed = t2.speed and t1.ram = t2.ram and t1.model != t2.model
輸出:
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
需要的輸出:
model model speed ram
1233 1121 750 128
1233 1232 500 64
1260 1232 500 32
那麼,如何避免(J,I)在我的輸出?
謝謝。
我給予好評AIX和伊什塔爾,但我會去伊什塔爾;將'!='更改爲'>'。 – MatBailie 2011-05-19 14:42:31