Sql Query for below problem [closed]
i have one table having data as mentioned be开发者_Go百科low:
Name
----
ram
ram
ram
sita
sita
sita
now i need out put like below:
ram
sita
ram
sita
ram
sita
is any one know the answer?
You can do this with the analytic function ROW_NUMBER():
select name from
( select name
, row_number() over (partition by name order by id) as rn
from your_table
order by rn, name
/
You will need a column to order the names: I've proposed ID but don't know what columns your table has.
The above is the Oracle syntax. T-SQL may support different syntax.
declare @T table(Name varchar(5))
insert into @T values
('ram'),
('ram'),
('ram'),
('sita'),
('sita'),
('sita')
select Name
from @T
order by row_number() over(partition by Name order by Name), Name
精彩评论