Order by a calculated column : Order By « Query Select « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
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
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 Tutorial » Query Select » Order By 
2. 4. 7. Order by a calculated column
SQL>
SQL> CREATE TABLE titles(
  2    title_id   CHAR(3)      NOT NULL,
  3    title_name VARCHAR(40)  NOT NULL,
  4    type       VARCHAR(10)  NULL    ,
  5    pub_id     CHAR(3)      NOT NULL,
  6    pages      INTEGER      NULL    ,
  7    price      DECIMAL(5,2NULL    ,
  8    sales      INTEGER      NULL    ,
  9    pubdate    DATE         NULL    ,
 10    contract   SMALLINT     NOT NULL
 11  );

Table created.

SQL>
SQL>
SQL>
SQL>
SQL> INSERT INTO titles VALUES('T01','Java','history','P01',111,21.99,566,DATE '2000-08-01',1);

row created.

SQL> INSERT INTO titles VALUES('T02','Oracle','history','P03', 114,19.95,9566,DATE '1998-04-01',1);

row created.

SQL> INSERT INTO titles VALUES('T03','SQL','computer','P02', 122,39.95,25667,DATE '2000-09-01',1);

row created.

SQL> INSERT INTO titles VALUES('T04','C++','psychology','P04', 511,12.99,13001,DATE '1999-05-31',1);

row created.

SQL> INSERT INTO titles VALUES('T05','Python','psychology','P04', 101,6.95,201440,DATE '2001-01-01',1);

row created.

SQL> INSERT INTO titles VALUES('T06','JavaScript','biography','P01', 173,19.95,11320,DATE '2000-07-31',1);

row created.

SQL> INSERT INTO titles VALUES('T07','LINQ','biography','P03', 331,23.95,1500200,DATE '1999-10-01',1);

row created.

SQL> INSERT INTO titles VALUES('T08','C#','children','P04', 861,10.00,4095,DATE '2001-06-01',1);

row created.

SQL> INSERT INTO titles VALUES('T09','SQL Server','children','P04', 212,13.95,5000,DATE '2002-05-31',1);

row created.

SQL> INSERT INTO titles VALUES('T10','AJAX','biography','P01', NULL,NULL,NULL,NULL,0);

row created.

SQL> INSERT INTO titles VALUES('T11','VB','psychology','P04', 821,7.99,94123,DATE '2000-11-30',1);

row created.

SQL> INSERT INTO titles VALUES('T12','Office','biography','P01', 507,12.99,100001,DATE '2000-08-31',1);

row created.

SQL> INSERT INTO titles VALUES('T13','VBA','history','P03', 812,29.99,10467,DATE '1999-05-31',1);

row created.

SQL>
SQL>
SQL>
SQL>
SQL> SELECT title_id,
  2         price,
  3         sales,
  4         price * sales AS "Revenue"
  5    FROM titles
  6    ORDER BY "Revenue" DESC;

TIT      PRICE      SALES    Revenue
--- ---------- ---------- ----------
T10
T07      23.95    1500200   35929790
T05       6.95     201440    1400008
T12      12.99     100001 1299012.99
T03      39.95      25667 1025396.65
T11       7.99      94123  752042.77
T13      29.99      10467  313905.33
T06      19.95      11320     225834
T02      19.95       9566   190841.7
T04      12.99      13001  168882.99
T09      13.95       5000      69750

TIT      PRICE      SALES    Revenue
--- ---------- ---------- ----------
T08         10       4095      40950
T01      21.99        566   12446.34

13 rows selected.

SQL>
SQL> drop table titles;

Table dropped.

SQL>
SQL>
2. 4. Order By
2. 4. 1. Sorting Rows Using the ORDER BY Clause
2. 4. 2. Sort last name ascending
2. 4. 3. Sort last name descending
2. 4. 4. Sort one column ascending and another column descending
2. 4. 5. Sort by index ascending and descending
2. 4. 6. Reference alias name in order by clause
2. 4. 7. Order by a calculated column
2. 4. 8. Sort the rows by descending order with DESC appended to order by clause
2. 4. 9. Sort two columns with different ordering
2. 4. 10. Use a column position number in the ORDER BY clause
2. 4. 11. A SELECT with Ordering
2. 4. 12. Order the table on the employee's original salary (orig_salary)
2. 4. 13. Order by two columns
2. 4. 14. Add aggregate function in order by clause
2. 4. 15. Order by username
2. 4. 16. Combine order by clause with case statement
2. 4. 17. Order Your Email
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.