在 SQL 中处理多个硬编码值的最简单方法?
我将如何在 SQL Server 中执行此操作?(我知道它不会像写的那样运行,但它比我能解释的更好地说明了这个问题)
How would I do this in SQL Server? (I know it won't run as written but it illustrates the question better than I can explain)
SELECT SQRT(number) WHERE number IN (4,9,16,25)
当然会返回多行
推荐答案
您可以使用 表值构造器
select sqrt(number)
from (
values (4),(9),(16),(25)
) as T(number)
或使用 union all
select sqrt(number)
from (
select 4 union all
select 9 union all
select 16 union all
select 25
) as T(number)
sql 小提琴演示
相关文章