2

我有以下数据库,我需要列出所有subno,subname,其中配额大于subno 30012的配额。

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?

4

1 回答 1

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)
于 2013-04-22T00:24:54.183 回答