Submitted Questions

  • Get 10 and 11th records in the output using SQL in 5 ways ?

    I have to tables A and B. My records in this table are in such a way that Table A Table B 10 15 11 16 12 10 13 11 Question :- I want only the 10 and 11 records as my output. Can anyone help me out ( 5 ways to get this output )

    hussain

    • Mar 29th, 2012

    Code
    1. SELECT * FROM emp WHERE (rowed,0) IN (SELECT rowid,mod(rownum,5) FROM emp);

    SivaKumar

    • Mar 23rd, 2012

    Method 1

    Code
    1. SELECT a,employee_id,last_name,first_name,salary FROM
    2. (SELECT ROWNUM AS a,employee_id,last_name,first_name,salary FROM employees)
    3. WHERE a BETWEEN 10 AND 11

  • SQL - Find top two salary for each department

    1. top 2 salary in each dept2. 2nd maximum sal in each dept3. 2nd minimum sal in each dept.

    Prasanth

    • Sep 12th, 2022

    SELECT d.department_id, d.salary, d.employee_id FROM
    (SELECT employee_id, department_id, salary, dense_rank() over(partition by department_id order by salary desc ) as salary_DenseRank from employees) d
    WHERE d.salary_DenseRank =2;