sequence 1, 2, 3, 3, 2, 1 v2

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

DECLARE @n int = 3;
DECLARE @m int = 4;

WITH numbers(v) AS(
	SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL))
	FROM (VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9)) AS n0(x)
)
SELECT ord = @n*(v+2*m) + n
	, n*(1-v) + ABS(-@n-1+n)*v
FROM (SELECT TOP(@n) v FROM numbers ORDER BY v ASC) n(n)
CROSS JOIN (VALUES(0), (1)) AS s(v)
CROSS JOIN (SELECT TOP(@m) v-1 FROM numbers ORDER BY v ASC) m(m)
ORDER BY ord

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results