關於資料庫的問題 - 考試

Table of Contents

Employee(E#,E_name,E_address,E_salary)

Works_On(E#,P#,hours)

project(P#,P_name)

問:列出所有做了三個(含)以上的計劃的員工,他們的名字和薪水

唐箏的解法: Select E_name,E_salary
From Employee
Whrer E# In
(Select E#
From works_on
Group By E#
Having count(*)>=3
);

函授課程中,他自己說這個解法,在子查詢中少了where條件,要學生自己寫

還說不會寫的考不上....我就是那個不會寫的XDD


有人知道where條件缺什麼嗎?

是不是少了 Where Employee.E# = works_on.E# ??

如果是少了這個,覺得滿疑惑的

我自己是覺得

子查詢已經可以靠 Group By E# 和 Having count(*) 查詢出誰做了三個以上的計畫

並且 Select E# 會顯示出這些人的 E# 給上一層的 where

如此為什麼還要再子查詢裡面加where條件?

----------------------------------------------------------------------------

或者他的意思是最上層 where 少了條件??

請高手解惑

謝謝



--

All Comments

Candice avatarCandice2013-04-27
你寫的where條件把E改成P
Tristan Cohan avatarTristan Cohan2013-04-28
改成works_on.p#=project.p#
Edith avatarEdith2013-05-01
答案是 不用寫WHERE的條件 硬要寫就WHERE '1'='1'
Todd Johnson avatarTodd Johnson2013-05-03
我指的是內部不需要WHERE 外部也已經有了
Selena avatarSelena2013-05-04
Your anser is solution 2 and it is correct. The answer
Rachel avatarRachel2013-05-08
in the textbook lack the "where ..." sentence.
Anonymous avatarAnonymous2013-05-11
樓上正解
Edwina avatarEdwina2013-05-11
這題不用使用PROJECT就可以解了
Aaliyah avatarAaliyah2013-05-14
那個解法就是對的阿 有少條件嗎?
Tom avatarTom2013-05-16
我覺得是要針對同一個表格查詢,如果有多個表格可能會出錯
Thomas avatarThomas2013-05-16
所以在進行多個表格查詢必須把這幾個表格JOIN起來成1個表
Valerie avatarValerie2013-05-18
我怎麼記得IN裡面的子查詢不用特別加
Barb Cronin avatarBarb Cronin2013-05-19
Employee.E#=Works_on.E#,是EXIST才規定一定要加吧~
Steve avatarSteve2013-05-19
那個解法就是對的阿 有 https://daxiv.com