是否可以从查询中设置/读取变量?
伪代码:
SELECT animal_name,
@tallest_animal = (select top 1 height from animal order by height desc) as tallest,
@smallest_animal = (select top 1 height from animal order by height asc) as smallest
FROM animals
WHERE height BETWEEN @smallest_animal AND @tallest_animal
我知道可以通过使查询不同来实现结果,我的问题的实际用途很难解释。
这是有问题的 Microsoft SQL Server。:)