DECODE of Oracle learning notes and common window functions

Source: Internet
Author: User

OracleDatabaseDECODEImplement row-column conversion andCommon window functionsThe related knowledge is what we will introduce in this article. I hope this introduction will be helpful to you!

Use DECODE to convert rows and columns

The Code is as follows:

 
 
  1. Select 'payroll 'department,
  2. Sum (decode (k. deptno, '10', k. g)
  3. , Sum (decode (k. deptno, '20', k. g) B
  4. , Sum (decode (k. deptno, '30', k. g) C
  5. , Sum (decode (k. deptno, '40', k. g) D
  6. From (select sum (e. sal) g, e. deptno from emp e
  7. Left join dept d on d. deptno = e. empno
  8. Group by e. deptno) k;

Oracle window functions

 
 
  1. Rank () over (order by emp_age)
  2. Dense_rank () over (order by emp_age)
  3. Row_number () over (order by emp_age)
  4. Avg (age) over (partition by position) avg
  5. Sum (age) over (order by age rows between 1 preceding and 1 following) -- get the first and last rows of the current record
  6. Count (1) over (order by age range between 1 preceding and 1 following) c -- the difference is one year old.

Here is an introduction to Oracle Database DECODE and common window functions. I hope this introduction will be helpful to you!

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.