SQL query Topics

Source: Internet
Author: User

--1 and enquiries about employees who entered the company in 1981
SELECT *
From EMP
where hiredate between ' January-January-1981 '
and ' 3 January-December-1981 ';

SELECT *
From EMP
where HireDate >= ' January-January-1981 '
and HireDate <= ' 3 January-December-1981 ';
--2, query Manager number not 7902 of employees
SELECT *
From EMP
where mgr! = 7902;

SELECT * FROM emp
where Mgr <> 7902;


--3, Fuzzy query
--Query employee information for the first letter in the name is S
--% characters 0 to any bit
1 bits in the--_ character
--like
SELECT * FROM emp
where ename like ' s% ';
--Query employee information for the second letter L
SELECT * FROM emp
where ename like ' _l% ';
--Query employee information with s in the name
SELECT * FROM emp
where ename like '%s% ';

--4, Query 7698, 7788, 7902 management of employee information
SELECT * FROM emp
where mgr = 7698 or mgr = 7788 or mgr = 7902;

SELECT * FROM emp
where Mgr in (7698,7788,7902);

--5 employee information that pays better than Jones's salary
SELECT * FROM emp
where Sal >
(Select Sal from emp
where ename = ' JONES ');

--6, the number of employees in the employee table, the total wage, the maximum wage, the minimum wage, the average wage
Select COUNT (*), sum (SAL), Max (Sal), Min (sal), avg (SAL)
from EMP;
--7, find information about employees and your department
--Descartes Product
SELECT * FROM Emp,dept
where Emp.deptno = Dept.deptno;

--8, query employee information and the department's information, request to have no staff of the department also to show out
SELECT * FROM Emp,dept
where Emp.deptno (+) = Dept.deptno

--9, query employee information and manager information
SELECT * FROM emp a,emp b
where A.mgr=b.empno (+);

SQL query Topics

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.