Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sort by the sum of two columns in an SQL Table

Posted on 2007-11-27
2
Medium Priority
?
2,728 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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup
Suggested Courses

810 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