Dynamic WebsitesPHP with Oracle DB   By Belal Arfa
Section 4In this section will discuss  1- SQL Practical Examples
ExamplesSchema:Beers(name, made_by)Bars(name, addr, license)Drinkers(name, addr, phone)Likes(drinker, beer)Sells(bar, beer...
Examples- The database is formed from 2 tables, CAR and DRIVER.- Each car may be owned by a DRIVER.- A DRIVER may own mult...
Examples- Find All Cars- Find Cars Reg. Numbers- Find Color and owner of each car- Find Reg. Number of Red Cars- Find all ...
Examples
Examples- Find Employees who dont live in London- Find Employees who live in London and Seattle and Redmon         ( IN,OR...
Examples               LOCATION                                   DEPARTMENT Location_ID             Regional_Group   Depa...
Examples                                                     EMPLOYEEEMPLOYEE_ID   LAST_NAME   FIRST_NAME   MIDDLE_NAME   ...
Examples- List all the employee details- List all the department details- List all job details- List all the locations- Li...
Examples- List out the employees who are working in department 10 or 20- Find out the employees who are not working in dep...
Examples- List out the department wise maximum salary, minimum salary,     average salary of the employees- List out the j...
Upcoming SlideShare
Loading in …5
×

Dynamic websites lec4

314 views

Published on

SQL Queries Examples

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
314
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dynamic websites lec4

  1. 1. Dynamic WebsitesPHP with Oracle DB By Belal Arfa
  2. 2. Section 4In this section will discuss 1- SQL Practical Examples
  3. 3. ExamplesSchema:Beers(name, made_by)Bars(name, addr, license)Drinkers(name, addr, phone)Likes(drinker, beer)Sells(bar, beer, price)Frequents(drinker, bar)Question:What beers are made by John Smith?Answer: SELECT name FROM Beers WHERE made_by= John Smith;Note single quotes for strings.
  4. 4. Examples- The database is formed from 2 tables, CAR and DRIVER.- Each car may be owned by a DRIVER.- A DRIVER may own multiple CARs. Driver CarDriver Car REGNO Make Color Price Owner NAME DOB F611AAA FORD RED 12000 Jim Smith Jim Smith 11 Jan 1980 J111BBB SKODA BLUE 11000 Jim Smith Bob Smith 23 Mar 1981 A155BDE MERCEDES BLUE 22000 Bob Smith Bob Jones 3 Dec 1986 K555GHT FIAT GREEN 6000 Bob Jones SC04BFE SMART BLUE 13000
  5. 5. Examples- Find All Cars- Find Cars Reg. Numbers- Find Color and owner of each car- Find Reg. Number of Red Cars- Find all drivers born between 1995 and 1999- Find Cars Reg. Numbers which price between 5000 and 12000- Find Cars with no owners ( select regno from car where owner is NULL)- Find Cars Owned by Jim Smith- Find Cars which colors are green and red- Find the car which has the maximum price- Find the summation of cars prices- Find the count of cars which have color blue
  6. 6. Examples
  7. 7. Examples- Find Employees who dont live in London- Find Employees who live in London and Seattle and Redmon ( IN,OR)- Find Employees in ascending order of city and descending order of country- Find Employees that their first name doesnt start with M- Find Employees that their salary are less than 1500- Find Numbers of employees
  8. 8. Examples LOCATION DEPARTMENT Location_ID Regional_Group Department_ID Name Location_ID 122 NEW YORK 10 ACCOUNTING 122 123 DALLAS 20 RESEARCH 124 124 CHICAGO 30 SALES 123 167 BOSTON 40 OPERATIONS 167 JOBJob_ID Function 667 CLERK 668 STAFF 669 ANALYST 670 SALESPERSON 671 MANAGER 672 PRESIDENT
  9. 9. Examples EMPLOYEEEMPLOYEE_ID LAST_NAME FIRST_NAME MIDDLE_NAME JOB_ID MANAGER_ID HIREDATE SALARY COMM DEPARTMENT_I D 7369 SMITH JOHN Q 667 7902 17-DEC- 800 NULL 20 84 7499 ALLEN KEVIN J 670 7698 20-FEB- 1600 300 30 85 7505 DOYLE JEAN K 671 7839 04-APR- 2850 NULL 30 85 7506 DENNIS LYNN S 671 7839 15-MAY- 2750 NULL 30 85 7507 BAKER LESLIE D 671 7839 10-JUN- 2200 NULL 40 85 7521 WARK CYNTHIA D 670 7698 22-FEB- 1250 500 30 85
  10. 10. Examples- List all the employee details- List all the department details- List all job details- List all the locations- List out first name,last name,salary, commission for all employees- List out employee_id,last name,department id for all employees and rename employee id as “ID of the employee”, last name as “Name of the employee”, departmentid as “department ID”- List out the employees annual salary with their names only.- List the details about “SMITH”- List out the employees who are working in department 20- List out the employees who are earning salary between 3000 and 4500
  11. 11. Examples- List out the employees who are working in department 10 or 20- Find out the employees who are not working in department 10 or 30- List out the employees whose name starts with “S”- list out the employees who are not receiving commission.- List out the employee id, last name in ascending order based on the employee id. - List out the employee id, name in descending order based on salary column- list out the employee details according to their last_name in ascending order and salaries in descending order- How many employees who are working in different departments wise in the organization
  12. 12. Examples- List out the department wise maximum salary, minimum salary, average salary of the employees- List out the job wise maximum salary, minimum salary, average salaries of the employees- Display the employee who got the maximum salary.- Display the employees who are working in Sales department- Display the employees who are working as “Clerk”.- Display the employees who are working in “New York”- Update the employees salaries, who are working as Clerk on the basis of 10%.- Delete the employees who are working in accounting department.- Create trigger on employees on save make comm = 0.25 of salary

×