2013-04-22 91 views
2

我有以下的數據庫,我需要列出所有subno,子名,其中配額比subno 30012.SQL - 如何列出值大於另一個單元格的單元格?

subno subname     quota 
30006 Adv Database design 300 
30007 Software fundamentals 200 
30008 Application Development 350 
30010 Database development 300 
30011 System design   200 
30012 Requirement engineering 350 

我知道配額更大,我可以做

select subno, subname from subject 
where quota > 350 

但如何我是否改變這一點以允許配額大於30012的配額而不是大於350?

回答

5

您使用子查詢:

select subno, subname from subject 
where quota > (select quota from subject where subno = 30012) 

這是假設只有一個一個給定subno可能的報價。如果有多個可能,則使用聚合函數,例如:

select subno, subname 
from subject 
where quota > (select max(quota) from subject where subno = 30012) 
相關問題