i presented question:
write sql command display each employee has total distance journeys of more 100, employee’s name, total number of litres used employee on journeys. (the number of litres journey distanceinkm divided kmperlitre.)
and i've more or less hit brick wall. had question similar earlier , user told me resolve inner join, , i've been doing since, question uniquely asks data 3 tables. solution:
select distinct e.name, sum(t.distanceinkm/c.kmperlitre) employe e, travelcost t, car c group t.distanceinkm,e.name,c.kmperlitre having sum(distanceinkm) > 100;
(please ignore small differences; employee table named employe , distancesinceservice column called "distance")
but gives me absolutely insane outputs , have no real clue what's happening. did group by's in class none of them difficult i'm bit stuck.
here version joins tables , should give expect
select e.name , sum(t.distanceinkm/c.kmperlitre) numlitres , sum(t.distanceinkm) totaldistanceinkm employe e inner join travelcost t on e.id = t.employeeid inner join car c on t.carregno = c.regno group e.name having sum(t.distanceinkm) > 100 ;
hope helps
Comments
Post a Comment