Solved

Sort by the sum of two columns in an SQL Table

Posted on 2007-11-27
2
2,679 Views
Last Modified: 2012-06-27
SELECT trip_no,c_pilot_no AS PILOT,flight_hrs,flight_hrs_wait AS WAIT_HRS,flight_hrs + flight_hrs_wait AS TOTAL
FROM c_charter
ORDER BY c_pilot_no ASC
ORDER BY flight_hrs + flight_hrs_wait DESC;

The last line of code, the ORDER BY, is not working like I thought it would.  I need this select query to be ordered by the TOTAL column as created above.  It lists out correctly, but I cannot get the query to be sorted in order by the TOTAL column.
0
Comment
Question by:josephdaviskcrm
2 Comments
 
LVL 1

Expert Comment

by:bobbymanocha
ID: 20359703
SELECT trip_no,c_pilot_no AS PILOT,flight_hrs,flight_hrs_wait AS WAIT_HRS,flight_hrs + flight_hrs_wait AS TOTAL
FROM c_charter
ORDER BY c_pilot_no ASC, flight_hrs + flight_hrs_wait DESC;
0
 
LVL 13

Accepted Solution

by:
sonicefu earned 500 total points
ID: 20363409
SELECT trip_no,c_pilot_no AS PILOT,flight_hrs,flight_hrs_wait AS WAIT_HRS,flight_hrs + flight_hrs_wait AS TOTAL
FROM c_charter
ORDER BY PILOT ASC, TOTAL DESC;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Repeat query 13 61
Require data to appear on a single line 2 68
run sql script from putty 4 62
Error in creating a view. 8 19
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question