1

i'm working with the airplanes, carriers and flight data base from the stat-computing.org

there is a Flights table with flights numbers (TailNum) and distances (Distance) for every flight

the SQL query that i working with is below:

it is quite simple and works fine, except that i got the sum of the Distance for all the flights in the first result row, and only after, the grouped result by TailNum. Why i got this first row with the total distance for all flights??

SELECT TailNum, SUM(Distance) AS totalDistance 
FROM Flights GROUP BY TailNum ORDER BY totalDistance DESC LIMIT 10;
4
  • 3
    share sample data and expected output Oct 24, 2019 at 10:01
  • 2
    Looks like there should be blank TailNum values
    – George G
    Oct 24, 2019 at 10:03
  • Thanks, @ZaynulAbadinTuhin, the expected output is the SUM by Distance aggregated by TailNum. How can i share the sample data? Oct 24, 2019 at 10:18
  • 1
    @RaulMagdalenaCatala edit your question to put in create table and insert into statements so people can easily copy and paste them.
    – Shawn
    Oct 24, 2019 at 10:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.