Declare @temp as Table ( ID INT PRIMARY KEY IDENTITY(1, 1),

0

Please login or register to vote for this query.

(click on this box to dismiss)

Android Enthusiasts

Q&A for enthusiasts and power users of the Android operating system

Declare @temp as Table
(
	ID INT PRIMARY KEY IDENTITY(1, 1),
	Direction Varchar(1),
	Bay INT,
	Y INT
)

INSERT INTO @temp
values ('L', 1, 5), ('R', 1, 5), ('R', 2, 10), ('L', 2, 15), ('L', 3, 20), 
('R', 3, 25), ('L', 4, 30), ('R', 4, 30)

Select *, 
DENSE_Rank() OVER (ORDER BY Y ASC) AS DenseRank,
(2 * (DENSE_Rank() OVER (ORDER BY Y ASC)) - 
  (
    CASE Direction WHEN 'L' THEN 1 ELSE 0 END
  )
) AS TranslatedBay
from @temp order by ID

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results