declare @Ordre table ( ordre_id int, code_dest char(1) ) ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Anime and Manga

Q&A for anime and manga fans

declare @Ordre table
(
  ordre_id int,
  code_dest char(1)
)
insert into @Ordre values
(1,'a'),
(2,'b'),
(3,'c'),
(4,'a'),
(5,'a'),
(6,'b'),
(7,'g')



select id_voit, ordre_id, rsOrdre.code_dest
from @Ordre rsOrdre
inner join 
(
  select distinct code_dest, ROW_NUMBER() over (order by code_dest) as id_voit
  from @Ordre
  group by code_dest
) rsVoit on rsVoit.code_dest = rsOrdre.code_dest
order by id_voit, ordre_id

Enter Parameters

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