4

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)

It would return multiple rows of course

4

2 回答 2

14

您可以使用表值构造函数

select sqrt(number) 
from (
    values (4),(9),(16),(25)
) as T(number)

或使用联合所有

select sqrt(number)
from (
    select 4 union all
    select 9 union all
    select 16 union all
    select 25
) as T(number)

sql fiddle demo

于 2013-09-16T17:02:38.357 回答
0

您可以创建一个派生表:

SELECT SQRT(number)
FROM (
    SELECT 4 AS number
    UNION ALL SELECT 9
    UNION ALL SELECT 16
    UNION ALL SELECT 25
) A
于 2013-09-16T17:00:58.993 回答