2016-07-24 83 views
-2

使用下面 http://i.imgur.com/rIMgFZC.png我的sql查詢是否正確?

表中檢索誰具有相同的E_level值墊大衛和也以相同的店作爲墊大衛工作的員工的名字。

SELECT E_fname,E_lname 
FROM Employee E, 
(SELECT E_Level 
FROM Employee E 
WHERE UPPER(E.E_lname) = ‘DAVID’ 
AND UPPER(E.Efname) = ‘MAT’) elevel, 
(SELECT E_Store_ID 
FROM Employee E 
WHERE UPPER(E.E_lname) = ‘DAVID’ 
AND UPPER(E.Efname) = ‘MAT’ 
) estoreid 
WHERE E.E_level = elevel.E_level 
AND E.Store_ID = estoreid.Store_ID 
AND UPPER(E.E_lname) != ‘DAVID’ 
AND UPPER(E.Efname) != ‘MAT’; 



SELECT E_fname,E_lname 
FROM EMPLOYEE E 
WHERE E.E_level = 
(SELECT E_level 
FROM Employee E 
WHERE UPPER(E.E_lname) = ‘DAVID’ 
AND UPPER(E.Efname) = ‘MAT’) 
AND E.E_Store_ID = 
(SELECT E_Store_ID 
FROM Employee E 
WHERE UPPER(E.E_lname) = ‘DAVID’ 
AND UPPER(E.Efname) = ‘MAT’) 
AND UPPER(E.E_lname) != ‘DAVID’ 
AND UPPER(E.Efname) != ‘MAT’; 

這些是我的嘗試。我對麼?

回答

0
SELECT E_fname,E_lname 
    FROM Employee E 
    WHERE E_level = (SELECT E_Level 
         FROM Employee E 
         WHERE UPPER(E.E_lname) = 'DAVID' 
          AND UPPER(E.E_fname) = 'MAT') 
     AND E_store_ID = (SELECT E_Store_ID 
         FROM Employee E 
          WHERE UPPER(E.E_lname) = 'DAVID' 
          AND UPPER(E.E_fname) = 'MAT' 
         ) 
     AND UPPER(E.E_lname) != 'DAVID' 
     AND UPPER(E.E_fname) != 'MAT';