I have an sql query to display all the sum of stage_times from the stage_time table. But I only require sum of stage_times for cars that have values entered for all 3 stages so car_no 3 is excluded from the list in this case;
Here is an sqlfiddle with my example code http://sqlfiddle.com/#!2/1675d/78
SELECT d.*, SUM(Stage_Time) AS total
FROM Driver d, Stage_Times st
WHERE st.Driver_Id = d.Driver_Id AND st.Event_Id = 1
AND st.Stage_Id <= 3
GROUP BY d.Driver_Id
ORDER BY total;
Thanks in advance for any help
You may just add an Having clause
having count(distinct st.Stage_id) = 3
see updated sqlfiddle
(by the way, I changed your query to use join, it's a better way to do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With