Solved

Sort by the sum of two columns in an SQL Table

Posted on 2007-11-27
2
2,637 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
Comment Utility
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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now