生成序列号取决于输入

时间:2017-05-22 05:00:50

标签: sql-server generate-series

请让我知道如何在SQL中生成以下系列,我输入并需要输出如: This is my Input and needed output

1 个答案:

答案 0 :(得分:0)

您可以像这样使用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