Complex query of a single Oracle table

Source: Internet
Author: User

Complex query of a single Oracle table

select avg(sal),max(sal),deptnofrom empgroupby deptno;

 

select avg(sal),max(sal),deptnofrom empgroupby deptnohavingavg(sal)>2000orderby deptno;

 

Query employees whose salaries are higher than 500 or whose positions are MANAGER and whose first letter is uppercase J? Select * from empwhere (sal> 500or job = 'manager') and enamelike 'J % '; select * from emporderby deptnoasc, saldesc; select (sal + nvl (comm, 0) * 12 assum, enamefrom emporderbysum; Calculate the highest wage and minimum wage selectmax (sal), min (sal) from emp; query the name of the highest-wage employee. select ename, salfrom empwhere (selectmax (sal) from emp) = sal; select * from empwhere sal> (selectavg (sal) from emp); group by and having clause group by are used for queries. The having clause is used to limit the display results of a group. How do I display the average and maximum salaries of each department selectavg (sal), max (sal), deptnofrom empgroupby deptno; display the average salary and minimum wage of each position in each department? Selectavg (sal), max (sal), min (sal), deptno, jobfrom empgroupby deptno, job; shows that the average salary is less than 2000 of the Department number and its average salary? Selectavg (sal), max (sal), deptnofrom empgroupby deptnohavingavg (sal)> 2000 orderby deptno;

 

Summary of Data grouping: 1 The grouping function can only appear in the selection list, having, order by clause (cannot appear in where) 2. If the select statement contains group, having, order by then their order is group by, having, order by3 in the selection column if there are columns, expressions and grouping functions, these columns and expressions must appear in the group by clause. Otherwise, an error occurs. For example
SELECT deptno, AVG(sal), MAX(sal) FROM emp GROUP by deptno HAVING AVG(sal) < 2000;

 


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.