Home > Software design >  Select number of completed trips by a plane
Select number of completed trips by a plane

Time:06-05

I'm suppose to select number of trips completed by plane TU-134. I'm doing basic exersices on some website.

SELECT plane, COUNT(trip) as numberOfTrips FROM Pass_in_trip
INNER JOIN Trip WHERE plane = 'TU-134'

This prints

plane TU-134 numberofTrips 128

But its still not correct why? I assume im not getting the completed trips?

Update with tables: enter image description here

CodePudding user response:

You need to fix your inner join statement and group data by plane so you can use count function.

Inner join

Group by

SELECT 
   Plane = T.plane, 
   NumberOfTrips = COUNT(P.trip)  
FROM       Pass_in_trip P
INNER JOIN Trip         T ON P.Trip= T.Id
WHERE 
   T.plane = 'TU-134'
GROUP BY
   T.plane
  •  Tags:  
  • sql
  • Related