利用SQL语句编写一段代码,实现从1到100之间的奇数和

2024-12-23 11:01:17
推荐回答(1个)
回答1:

sqlserver 2000:

SELECT SUM(rn) AS Expr1
FROM (SELECT (SELECT COUNT(*)
FROM sysobjects
WHERE id < a.id) AS rn
FROM sysobjects a) b
WHERE (rn <= 100) AND (rn % 2 <> 0)

结果是2500.