http://www.sql-tutorial.net/SQL-tutorial.asp http://www.sql-tutorial.net/SQL-Cheat-Sheet.pdf http://www.tizag.com/sqlTutorial/index.php http://beginner-sql-tutorial.com/ Create the following (4) Tables: 1.LOCATION 地點(ID,地區) LoID Region 122 NEW YORK 123 DALLAS 124 CHICAGO 167 BOSTON 2.DEPARTMENT 部門(ID,名稱,地點) DeptID Name LoID 10 ACCOUNTING 122 20 RESEARCH 124 30 SALES 123 40 OPERATIONS 167 3.JOB 工作(ID,職位) JobID Post 667 CLERK 668 STAFF 669 ANALYST 670 SALESPERSON 671 MANAGER 672 PRESIDENT 4.EMPLOYEE 顧員(ID,姓氏,名,名,職位,上司,入職日期,薪金,佣金,部門) empID LNAME FNAME MNAME JobID MANAGER HIREDATE SALARY COMM DeptID 7369 SMITH JOHN Q 667 7902 17-DEC-84 800 NULL 20 7499 ALLEN KEVIN J 670 7698 20-FEB-85 1600 300 30 7505 DOYLE JEAN K 671 7839 04-APR-85 2850 NULL 30 7506 DENNIS LYNN S 671 7839 15-MAY-85 2750 NULL 30 7507 BAKER LESLIE D 671 7839 10-JUN-85 2200 NULL 40 7521 WARK CYNTHIA D 670 7698 22-FEB-85 1250 500 30 7698 7839 7902 Queries based on the above tables: Simple Queries: 1. List all the employee details 列出所有員工資料 2. List all the department details 列出所有部門資料 3. List all job details 列出所有工作資料 4. List all the locations 列出所有地區資料 5. List out first name,last name,salary, commission for all employees 每個顧員姓名,薪金,佣金 6. List out empID,last name,department id for all employees and rename 更改顯示為 employee id as "ID of the employee", last name as "Name of the employee", department Id as "department ID" 7. List out the employees anuual salary with their names only. 顧員姓名、全年薪金 Where Conditions: 8. List the details about "SMITH" 某員工資料 9. List out the employees who are working in department 20 (部門20的所有員工) 10. List out the employees who are earning salary 薪金 3000-4500 11. List out the employees who are working in department 10 or 20 (部門10或20) 12. Find all employees who are not working in department 10 or 30 (部門10或30) 13. List out the employees whose name starts with "S" (名字: S開頭) 14. List out the employees whose name start with "S" and end with "H" (名字: S?..?H) 15. List out the employees whose name length is 4 and start with "S" (名字: Sxxx) 16. List out the employees who are working in department 10, with salaries more than 3500 (部門20,薪金多於3500) 17. list out the employees who are not receiving commission. 沒有佣金的員工 Order By Clause: 18. List out the employee id, last name in ascending order based on the employee id. 19. List out the employee id, name in descending order based on salary column 20. list out the employee details according to their LNAME in ascending order and salaries in descending order 21. list out the employee details according to their LNAME in ascending order and then on DeptID in descending order. Group By & Having Clause: 22. How many employees are working in different departments wise in the organization 23. List out the department wise maximum salary, minimum salary, average salary of the employees 24. List out the job wise maximum salary, minimum salary, average salaries of the employees. 25. List out the no.of employees joined in every month in ascending order. 26. List out the no.of employees for each month and year, in the ascending order based on the year, month. 27. List out the department id having at least four employees. 28. How many employees in January. 29. How many employees joined in January or September. 30. How many employees joined in 1985. 31. How many employees joined each month in 1985. 32. How many employees joined in March 1985. 33. Which is the department id, having greater than or equal to 3 employees joined in April 1985. Sub-Queries 34. Display the employee who got the maximum salary. 35. Display the employees who are working in Sales department 36. Display the employees who are working as "Clerk". 37. Display the employees who are working in "New York" 38. Find out no.of employees working in "Sales" department. 39. Update the employees salaries, who are working as Clerk on the basis of 10%. 40. Delete the employees who are working in accounting department. 41. Display the second highest salary drawing employee details. 42. Display the Nth highest salary drawing employee details Sub-Query operators: (ALL,ANY,SOME,EXISTS) 43. List out the employees who earn more than every employee in department 30. 44. List out the employees who earn more than the lowest salary in department 30. 45. Find out whose department has not employees. 46. Find out which department does not have any employees. Co-Related Sub Queries: 47.Find out the employees who earn greater than the average salary for their department. Joins Simple join 48.List our employees with their department names 49.Display employees with their designations (jobs) 50.Display the employees with their department name and regional groups. 51.Find the number of employees who are working in different departments and display with department name. 52.How many employees are working in sales department. 53.Which departments have greater than or equal to 5 employees and display the department names in ascending order. 54.How many jobs in the organization with designations. 55.How many employees working in "New York". Non—Equi Join: 56.Display employee details with salary grades. 57.List out the no. of employees on grade wise. 58.Display the employee salary grades and no. of employees between 2000 to 5000 range of salary. Self Join: 59.Display the employee details with their manager names. 60.Display the employee details who earn more than their managers salaries. 61.Show the no. of employees working under every manager. Outer Join: 61.Display employee details with all departments. 62.Display all employees in sales or operation departments. Set Operators: 63.List out the distinct jobs in Sales and Accounting Departments. 64.List out the ALL jobs in Sales and Accounting Departments. 65.List out the common jobs in Research and Accounting Departments in ascending order.