Capgemini interview question
Sql query: There is a table, called alphabet, a column in it as alpha, there are 6 rows in that column as a,b,c,d,e,f. I want to display feabcd in output
Interview Answers
I tried using order by and row_number function.
Select alpha from(
select t*,row_number() over(order by alpha desc) as r from alphabet) as t where r beteen 1 and 2
UNION ALL
Select alpha from(
select t*,row_number() over(order by alpha ) as r from alphabet) as t where r beteen 1 and 2
select alpha,
case
when alpha='a' then 'f'
when alpha='b' then 'e'
when alpha='c' then 'a'
when alpha='d' then 'b'
when alpha='e' then 'c'
when alpha='f' then 'd'
end
new_seq
from alphabet;
select * from alpha
order by
case
when id='f' then 'f'
when id='e' then 'e'
when id='a' then 'a'
end desc
Select * from alphabet order by --alpha desc case when alpha in ('e','f') then NULL Else alpha