The following fields are available in a table:
Assume that the table name is manage and the field name is Dan.
The Dan field has the following values:
Double
Single
Single
Single
Double
Double
Single
Question: How can I query the single-row first several times in the Dan field, then the dual-keys separated several times, and then the single
I used a subquery to simulate the cursor ~
After the following results are generated, a single order is generated several times in a row, and then a pair is generated several times. If a single order is displayed, you can simply summarize it, perform the following query as a derived table ~
-
SQL code
-
Declare @ t table (ID int, Dan varchar (20) insert @ t select 1, 'dual' Union all select 2, 'singles' Union all select 3, 'Single 'Union all select 4, 'double' Union all select 5, 'double' Union all select 6, 'singles' select Dan, count1 = (select count (1) + 1 from @ t B where Dan =. dan and ID = A.ID-1) from @ T