I have a question about sequence function in SQL Server.
First, I created a base table. Here is my code.
CREATE TABLE TEST2(
SEQ int IDENTITY (1, 1) NOT NULL,
Dates date,
CNT int,
)
INSERT INTO TEST2 (Dates, CNT)
VALUES
('2020-01-01', 0),
('2020-01-02', 0),
('2020-01-03', 0),
('2020-01-04', 1),
('2020-01-05', 0),
('2020-01-06', 1),
('2020-01-07', 0),
('2020-01-08', 0),
('2020-01-09', 0),
('2020-01-10', 0),
('2020-01-11', 0),
('2020-01-09', 2),
('2020-01-10', 0),
('2020-01-11', 0)
Here my attempt code.
CASE WHEN CNT != 0
THEN 0
ELSE CNT = 0
THEN (ROW_NUMBER() OVER(ORDER BY Dates))
END NEW_SEQ
It consists of two columns(Dates, CNT).
And I want to get the following result using the WHEN CASE expressions.
Here is my example results.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…