请告诉我如何在SQL中生成以下系列,我有输入并需要输出,例如:这是我的输入和所需的输出
你可以
像这样使用FLOOR
;WITH temp AS
(
SELECT row_number() over(ORDER BY n.t) AS Input
FROM (VALUES (1),(2), (3),(4),(5),(6),(7),(8),(9),(10)) AS n(t)
CROSS JOIN (VALUES (1),(2), (3),(4),(5),(6),(7),(8),(9),(10)) AS n1(t)
) -- return input table from 0 --> 100
SELECT t.Input, (FLOOR((t.Input - 1)/15) + 1) *15 AS Output
FROM temp t
演示链接:http://rextester.com/NYZ63298