Is our average total_order_price increasing or decreasing? : Aggregrate Analytical « Analytical Functions « Oracle PL / SQL

Oracle PL / SQL
1. Aggregate Functions
2. Analytical Functions
3. Char Functions
4. Constraints
5. Conversion Functions
6. Cursor
7. Data Type
8. Date Timezone
9. Hierarchical Query
10. Index
11. Insert Delete Update
12. Large Objects
13. Numeric Math Functions
14. Object Oriented Database
15. PL SQL
16. Regular Expressions
17. Report Column Page
18. Result Set
19. Select Query
20. Sequence
21. SQL Plus
22. Stored Procedure Function
23. Subquery
24. System Packages
25. System Tables Views
26. Table
27. Table Joins
28. Trigger
29. User Previliege
30. View
31. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL / SQL » Analytical Functions » Aggregrate Analytical 
Is our average total_order_price increasing or decreasing?
 
SQL>
SQL>
SQL> create table ord(
  2           order_no               integer          primary key
  3          ,cust_no                integer
  4          ,order_date             date not null
  5          ,total_order_price      number(7,2)
  6          ,deliver_date           date
  7          ,deliver_time           varchar2(7)
  8          ,payment_method         varchar2(2)
  9          ,emp_no                 number(3,0)
 10          ,deliver_name           varchar2(35)
 11          ,gift_message           varchar2(100)
 12  );

Table created.

SQL>
SQL>
SQL> insert into ord(order_no,cust_no,order_date,total_order_price,deliver_date,deliver_time,payment_method,emp_no,deliver_name,gift_message)
  2           values(1,1,'14-Feb-2002', 23.00'14-Feb-2002', '12 noon', 'CA',1, null, 'Gift for wife');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time ,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(2,1,'14-Feb-2003', 510.98'14-feb-2003', '5 pm', 'NY',7'Rose Ted', 'Happy Valentines Day to Mother');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(32,'14-Feb-2004', 315.99'14-feb-2004', '3 pm', 'VS',2'Ani Forest', 'Happy Valentines Day to Father');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(42,'14-Feb-1999', 191.95'14-feb-1999', '2 pm', 'NJ',2'O. John', 'Happy Valentines Day');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message    )
  2           values(56,'4-mar-2002', 101.95'5-mar-2002', '2:30 pm', 'MO'   2'Cora', 'Happy Birthday from John');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(69,'7-apr-2003', 221.95'7-apr-2003', '3 pm', 'MA', 2'Sake Keith', 'Happy Birthday from Joe' );

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(79,'20-jun-2004', 315.95'21-jun-2004', '12 noon', 'BC', 2'Jessica Li', 'Happy Birthday from Jessica');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values (812'31-dec-1999', 135.95'1-jan-2000', '12 noon', 'DI',      3'Larry', 'Happy New Year from Lawrence');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values (912'26-dec-2003', 715.95'2-jan-2004', '12 noon', 'SK',7'Did', 'Happy Birthday from Nancy' );

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(104, sysdate-1119.95, sysdate+2'6:30 pm', 'VG',2'P. Jing', 'Happy Valentines Day to Jason');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message )
  2           values(112, sysdate, 310.00, sysdate+2'3:30 pm', 'DC',2'C. Late', 'Happy Birthday Day to Jack');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2           values(127, sysdate-3121.95, sysdate-2'1:30 pm', 'AC',2'W. Last', 'Happy Birthday Day to You');

row created.

SQL> insert into ord(order_no  ,cust_no ,order_date ,total_order_price ,deliver_date ,deliver_time,payment_method ,emp_no,deliver_name ,gift_message)
  2           values(137, sysdate, 211.95, sysdate-4'4:30 pm', 'CA',2'J. Bond', 'Thanks for hard working');

row created.

SQL>
SQL>
SQL>
SQL> select order_no, order_date, total_order_price,
  2  avg(total_order_priceover order by order_date
  3                                range between interval '6' month preceding
  4                                and interval '6' month following AS annual_avg
  5  from ord
  6  order by order_Date
  7  /
  ORDER_NO ORDER_DATE           TOTAL_ORDER_PRICE ANNUAL_AVG
---------- -------------------- ----------------- ----------
         4 14-FEB-1999 00:00:00            191.95     191.95
         8 31-DEC-1999 00:00:00            135.95     135.95
         1 14-FEB-2002 00:00:00                23     62.475
         5 04-MAR-2002 00:00:00            101.95     62.475
         2 14-FEB-2003 00:00:00            510.98    366.465
         6 07-APR-2003 00:00:00            221.95    366.465
         9 26-DEC-2003 00:00:00            715.95 449.296667
         3 14-FEB-2004 00:00:00            315.99 449.296667
         7 20-JUN-2004 00:00:00            315.95 449.296667
        12 13-JUN-2008 18:00:55            121.95   190.9625
        10 15-JUN-2008 18:00:55            119.95   190.9625
        11 16-JUN-2008 18:00:55               310   190.9625
        13 16-JUN-2008 18:00:55            211.95   190.9625

13 rows selected.

SQL>
SQL> drop table ord;

Table dropped.

SQL> --

 
Related examples in the same category
1. count(*) over partition, order by, range unbounded preceding
2. count(*) over partition by, order by, range unbounded preceding
3. Employee salary report with avg salary for the previous 12 months
4. avg over range between
5. analytic order-by clause
6. avg over and avg over order by
7. Sum over order by
8. Sum over partition by and order by
9. avg over order by range
10. average 5 before, after
11. Row-ordering is done first and then the moving average
12. Avg over ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
13. SUM(y) OVER(ORDER BY x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
14. Use the COUNT aggregate analytical function to show how many rows are included in each window
15. To see how the moving average window can expand
16. Uses dates and logical offset of seven days preceding
17. A seven-day MAX and MIN on Tuesdays
18. A seven-day MAX and MIN on Tuesdays: using TO_CHAR function
19. Displaying a Running Total Using SUM as an Analytical Function
20. Reporting on a Sum
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.