Posts

sql group_concat(colname SEPARATOR '?')

  Emp_details_test has four columns EmpId,Gender,EmailId and DeptId.User has to write a sql query to dervie another column called Email_list to display all emailid concatenated with semicolon associated with each DEPT ID as shown below in ouput table. i:/p EMPID GENDER EMAILID DeptId 1001 M YYY@gmail.com 104 1002 M ZZ@gmail.com 103 1003 F AAAA@gmail.com 102 1004 F PP@gmail.com 104 1005 M CCCC@gmail.com 101 1006 M EEE@gmail.com 100 1007 F FGH@gmail.com 102 1008 M YYY@gmail.com 102 1009 F RAm@gmail.com 100

Sql->lag() ->read the previous record data.

 Student Table has three columns Student_Name,Total_Marksand year.User has to write a sql Query to display Student_Name,Total_Marks,Prev_yr_mrks for those whose total_marks are greater than or equal to the previous year i/p: Student_Name Total_Marks  year raghul 90    2010 Sanjay 80    2010 Mohan 70    2010 raghul 90    2011 Sanjay 85    2011 Mohan 65    2011 raghul 80    2012 Sanjay 80    2012 Mohan 90    2012 o/p: Student_Name  Total_Marks year  prev_yr_marks raghul 90    2010    90 Sanjay 80    2010    80 Mohan 70    2010    65 Create table Emp_details (  Student_Name varchar(10),  Total_Marks int,  year int  );   insert into emp_details values("raghul",90,2010); insert into emp_details values("Sanjay",80,2010); insert in...

Sql interview query

 Given below table emp as input which has two columns 'Group' and 'sequence'. Write a sql query to find the maximun and minimum values of continuous 'sequence' in each Group.

Sql interview question

Transaction_tbl table has four columns CusrId,TranID,TranAmt and Trandate. User has to display all these fileds alng with Maxiumn TranAmt for each CustID and ratio of TranAmt and Maximum TanAmt for each Transaction. o/p: 1001 20001 10000 80000 0.1250 2020-04-25 1001 20002 15000 80000 0.1875 2020-04-25 1001 20003 80000 80000 1.0000 2020-04-25 1001 20004 20000 80000 0.2500 2020-04-25 1002 30001 7000 22000 0.3182 2020-04-25 1002 30002 15000 22000 0.6818 2020-04-25 1002 30003 22000 22000 1.0000 2020-04-25