2013-09-26 34 views
1

嗨,我需要一些幫助,我有一個表銷售如下..我想比較它本身,並顯示結果公司應該不等於公司和價格應該等於價格..我已經嘗試了許多查詢在MySQL中,但沒有得到所需的結果,請幫助我做到這一點!告訴正確的查詢 將非常感謝你們!如何比較一個表與自己在一個條件下的mysql

sells(company,drink,price) 

查詢我試圖

mysql>'select company,drink,price from sells JOIN s ON(price=price1) where (comp 
any1!=company);' 

而s的賣出

+----------------+----------------+-------+ 
| company  | drink   | price | 
+----------------+----------------+-------+ 
| PepsiCo  | Mirinda  | 45 | 
| PepsiCo  | Pepsi   | 45 | 
| Coca-Cola  | Coca-cola zero | 45 | 
| Nestle   | Nescafe  | 35 | 
| Nestle   | Nescafe  | 35 | 
| Nestle   | Nescafe  | 35 | 
| Nestle   | Nescafe  | 35 | 
| Nestle   | Nescafe  | 35 | 
| Nestle   | Nescafe  | 35 | 
| Coca-Cola  | Coca-cola zero | 45 | 
| Shezan   | Twister  | 25 | 
| Nestle   | Fruita vitals | 25 | 
| Murree Brewery | Big Apple  | 35 | 
| Murree Brewery | Big Lemon  | 35 | 
| Murree Brewery | Big Orange  | 35 | 
| Murree Brewery | Peach Malt  | 35 | 
| Murree Brewery | Lemon Malt  | 35 | 
| Murree Brewery | Apple Malt  | 35 | 
+----------------+----------------+-------+ 

回答

-1

的副本表試試這個?

SELECT T1.company, T2.company, T1.price 
FROM sells T1 
JOIN sells T2 
WHERE 
T1.company != T2.company 
AND 
T1.price = T2.price 
GROUP BY T1.company, T1.price; 
+0

謝謝:)它的工作 但你能解釋一下這個請 –