gpt4 book ai didi

sql - 在 SQL 中处理多个硬编码值的最简单方法?

转载 作者:行者123 更新时间:2023-12-03 01:13:41 24 4
gpt4 key购买 nike

我该如何在 SQL Server 中执行此操作? (我知道它不会按书面方式运行,但它比我能解释的更好地说明了问题)

SELECT SQRT(number) WHERE number IN (4,9,16,25)

它当然会返回多行

最佳答案

您可以使用table value constructor

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 fiddle demo

关于sql - 在 SQL 中处理多个硬编码值的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18833428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com