question

new_man avatar image
new_man asked

Filter data in a table

Dears i have table that contains the following columns: ======================================================================================= ![alt text][1] --------------------------------------------------------------------------------------------- i need to filter the data in another table to be like the following result: --------------------------------------------------------------------------------------------- ![alt text][2] as you see with condition if charcater repeated select highest ID. [1]: /storage/temp/4201-input.jpg [2]: /storage/temp/4202-output.jpg
sqltablefilter
input.jpg (14.6 KiB)
output.jpg (13.9 KiB)
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
borispinsky avatar image
borispinsky answered
DECLARE @T table (ID int identity, Type varchar(5)) insert into @T(Type) values ('A'),('11'),('22'),('33'),('B'),('44'),('55'),('C'),('D'),('55'),('66'),('E'),('F'),('G'),('77'); with cte as (select * from @t where ascii(TYPE) between 65 and 90) select t.id , ( select type from cte where id = (select max(id) from cte where id < t.id) ) Type, t.Type value from @t t where id not in (select id from cte)
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.