ORACLE SQL Exercise (v)

Source: Internet
Author: User

--date converted to string


SELECT Date_hire, To_char (Date_hire, ' Month dd yyyy ') HIRE

From Employee_pay_tbl;



SELECT Employee_tbl. emp_id,

Employee_tbl. Last_Name,

Employee_pay_tbl. POSITION

From Employee_tbl, EMPLOYEE_PAY_TBL

WHERE Employee_tbl. emp_id = Employee_pay_tbl. emp_id;


SELECT E.emp_id,ep. Salary,ep. Date_hire,e.last_name

From Employee_tbl e,employee_pay_tbl EP

WHERE e.emp_id = EP. emp_id

and EP. SALARY > 20000;


SELECT e.emp_id,e.last_name,p.position

From Employee_tbl e,employee_pay_tbl P

WHERE e.emp_id <> p.emp_id;


The outer join returns all records in a table, even if the corresponding record does not exist in the second table.


SELECT P.prod_desc, O.qty

From Products_tbl P, Orders_tbl O

WHERE p.prod_id = o.prod_id;

-Show all products, regardless of whether they have orders


--oracle SQL syntax

SELECT P.prod_desc, O.qty

From Products_tbl P, Orders_tbl O

WHERE p.prod_id = o.prod_id (+); --Table with ' + ' is a table with no matching records


--ansi SQL syntax

SELECT P.prod_desc, O.qty

From Products_tbl P

Left JOIN orders_tbl O

on p.prod_id = o.prod_id;


--Self-coupling

-When the required data is in the same table, and we have to make some comparisons to the records, we can use the self-coupling.


--list the names of employees and their supervisors


SELECT E1.name,e2.name

From EMP e1,emp E2

WHERE E1. mgr_id = E2. emp_id


The--e1 table can be seen as a table that holds employee information, and the E2 table is the table that holds the supervisor information.



--Using the base table


SELECT C.cust_name, P.prod_desc

From Customer_tbl C, Products_tbl P, Orders_tbl O

WHERE c.cust_id = o.cust_id

and p.prod_id = o.prod_id;

SELECT e.city, AVG (EP. SALARY)

From Employee_tbl E, Employee_pay_tbl EP

WHERE e.emp_id = EP. emp_id

GROUP by E.city;


SELECT e.emp_id, E.last_name, E.first_name, EP. SALARY, EP. BONUS

From Employee_tbl E

JOIN Employee_pay_tbl EP

On e.emp_id = EP. emp_id;


This article from "Technology Station" blog, declined reprint!

ORACLE SQL Exercise (v)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.