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

Anonymous

27 Aug 2018

I tried using order by and row_number function.

11

Anonymous

29 May 2019

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

1

Anonymous

30 May 2019

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;

4

Anonymous

10 Oct 2019

Use analytical function

4

Anonymous

14 Nov 2019

select * from alpha order by case when id='f' then 'f' when id='e' then 'e' when id='a' then 'a' end desc

Anonymous

5 Sept 2019

Select * from alphabet order by --alpha desc case when alpha in ('e','f') then NULL Else alpha