You are on page 1of 3

1.Query for retrieving N highest paid employees FROM each Department. 2.

Query that will display the total no. of employees, and of that total the numb er who werehired in 1980, 1981, 1982, and 1983. 3.Query for listing Deptno, ename, sal, SUM(sal in that dept). 4.Matrix query to display the job, the salary for that job based on department n umber,andthe total salary for that job for all departments. 5.Nth Top Salary of all the employees. 6.Retrievingthe Nth row FROM a table. 7.Tree Query. 8.Eliminate duplicates rows in a table. 9.Displaying EVERY Nth row in a table. 10. Top N rows FROM a table. 11. COUNT/SUM RANGES of data values in a column. 12. For equal size ranges it might be easier to calculate it with DECODE(TRUNC(v alue/range),0, rate_0, 1, rate_1, ...). 13. Count different data values in a column. 14. Query to get the product of all the values of a column. 15. Query to display only the duplicate records in a table. 16. Query for getting the following output as many number of rows in the table. 17. Function for getting the Balance Value. 18. Function for getting the Element Value. 19. SELECT Query for counting No of words. 20. Function to check for a leap year. 21. Query for removing all non-numeric. 22. Query for translating a column values to INITCAP. 23. Function for displaying Rupees in Words. 24.Function for displaying Numbers in Words 25. Query for deleting alternate eve n rows FROM a table. 26. Query for deleting alternate odd rows FROM a table. 27. Procedure for sending Email. 28. Alternate Query for DECODE function. 29. Create table adding Constraint to a date field to SYSDATE or 3 months later. 30. Query to list all the suppliers who r supplying all the parts supplied by su pplier 'S2'. 31. Query to get the last Sunday of any month. 32. Query to get all those who have no children themselves. 33. Query to SELECT last N rows FROM a table. 34. SELECT with variables. 35. Query to get the DB Name. 36. Getting the current default schema. 37. Query to get all the column names of a particular table. 38. Spool only the query result to a file in SQLPLUS. 39. Query for getting the current SessionID. 40. Query to display rows FROM m to n. 41. Query to count no. Of columns in a table. 42. Procedure to increase the buffer length. 43. Inserting an & symbol in a Varchar2 column. 44. Removing Trailing blanks in a spooled file. 45. Samples for executing Dynamic SQL Statements. 46. Differences between SQL and MS-Access. 47. Query to display all the children, sub children of a parent. 48. Procedure to read/write data from/to a text file. 49. Query to display random number between any two given numbers. uery for retrieving N highest paid employees FROM each Department. 2.Query that will display the total no. of employees, and of that total the number who werehi red in 1980, 1981, 1982, and 1983. 3.Query for listing Deptno, ename, sal, SUM(s al in that dept). 4.Matrix query to display the job, the salary for that job bas ed on department number,andthe total salary for that job for all departments. 5. Nth Top Salary of all the employees. 6.Retrievingthe Nth row FROM a table.

7.Tree Query. 8.Eliminate duplicates rows in a table. 9.Displaying EVERY Nth row in a table. 10. Top N rows FROM a table. 11. COUNT/SUM RANGES of data values in a column. 12. For equal size ranges it might be easier to calculate it with DECODE(TRUNC(value/range),0, rate_0, 1, rate_1, ...). 13. Count different data v alues in a column. 14. Query to get the product of all the values of a column. 15. Query to display only the duplicate records in a table. 16. Query for getting the following output as many number of rows in the table. 17. Function for getting the Balance Value. 18. Function for getting the Element Value. 19. SELECT Query for counting No of words. 20. Function to check for a leap year. 21. Query for removing all non-numeric. 22. Query for translating a column values to INITCAP. 23. Function for displaying Rupees in Words. 24.Function for displaying Numbers in Words 25. Query for deleting alternate eve n rows FROM a table. 26. Query for deleting alternate odd rows FROM a table. 27. Procedure for sending Email. 28. Alternate Query for DECODE function. 29. Create table adding Constraint to a date field to SYSDATE or 3 months later. 30. Query to list all the suppliers who r supplying all the parts supplied by su pplier 'S2'. 31. Query to get the last Sunday of any month. 32. Query to get all those who have no children themselves. 33. Query to SELECT last N rows FROM a table. 34. SELECT with variables. 35. Query to get the DB Name. 36. Getting the current default schema. 37. Query to get all the column names of a particular table. 38. Spool only the query result to a file in SQLPLUS. 39. Query for getting the current SessionID. 40. Query to display rows FROM m to n. 41. Query to count no. Of columns in a table. 42. Procedure to increase the buffer length. 43. Inserting an & symbol in a Varchar2 column. 44. Removing Trailing blanks in a spooled file. 45. Samples for executing Dynamic SQL Statements. 46. Differences between SQL and MS-Access. 47. Query to display all the children, sub children of a parent. 48. Procedure to read/write data from/to a text file. 49. Query to display random number between any two given numbers. 50. Time difference between two date columns. 51. Using INSTR and SUBSTR 52. View procedure code 53. To convert signed number to number in oracle 54. Columns of a table 55. Delete rows conditionally 56.CLOB to Char 57.Change Settings 58.Double quoting a Single quoted String 59.Time Conversion 60.Table comparison 61.Running Jobs 62.Switching Columns 63.Replace and Round 64.First date of the year

65.Create Sequence 66.Cursors 67.Current Week 68. Create Query to restrict the user to a single row. 69. Query to get the first inserted record FROM a table. 70. Concatenate a column value with multiple rows. 71. Query to delete all the tables at once. 72. SQL Query for getting Orphan Records. 1. The following query retrieves "2" highest paid employees FROM each Department : SELECT deptno, empno, sal FROM emp e WHERE 2 > ( SELECT COUNT(e1.sal) FROM emp e1 WHERE e.deptno = e1.deptno AND e.sal < e1.sal ) ORDER BY 1,3 DESC; 2. Query that will display the total no. of employees, and of that total the num ber who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headin gs. I am looking at the following output. We need to stick to this format. Total 1980 1981 1982 1983 ----------- ------------ ------------ ------------- ---------- 14 1 10 2 1 SELECT COUNT (*),COUNT(DECODE(TO_CHAR (hiredate, 'YYYY'),'1980' , empno)) "1980", COUNT (DECODE (TO_CHAR (hiredate, 'YYYY'), '1981', empno)) "19 81", COUNT (DECODE (TO_CHAR (hiredate, 'YYYY'), '1982', empno)) "1982", COUNT (D ECODE (TO_CHAR (hiredate, 'YYYY'), '1983', empno)) "1983"

You might also like