1

我有一个包含名称、等级和分数的数据表。例如,“约翰”获得了 B 级,其分值为 3.0。

如何选择低于“B”级的条目?

所以我不知何故需要做这样的事情

Value = select Point from MyTable where Grade="B"

接着

select * from MyTable where Point < value

但显然 SQL 必须是一个语句......

4

2 回答 2

2

您可以嵌套选择并添加子查询:

SELECT realtable.* 
FROM (SELECT Point FROM MyTable WHERE Grade="B" LIMIT 1) subquery, MyTable realtable
WHERE subquery.Point > realtable.Point
于 2012-10-24T21:23:21.190 回答
1

Try it use in subquery as below:

select * 
from MyTable 
where Point < (select Point 
               from MyTable 
               where Grade="B")

but if you subquery returns more than one row try to use aggregate funcion for example min

select * 
from MyTable 
where Point < (select min(Point)
               from MyTable 
               where Grade="B")

or with LIMIT and join:

select * 
from MyTable mt
join (select Point from MyTable 
      where Grade="B"
      order by Point
      LIMIT 1) mt2 on mt.Point < mt2.Point
于 2012-10-24T21:15:52.843 回答