Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select Auto_Parts.Car_id,convert(varchar, Auto_Parts.Change_date,111) as Change_date,Service_Type.Servce_desc
,Auto_Parts.Current_dist,Auto_Parts.Prev_dist,(convert(float,Current_dist) - convert(float,Prev_dist)) as Change_dist
,(a.Value_Part) as Value,NULL as [Qty] from Auto_Part_Details a

JOIN (SELECT Car_id, MAX(Current_dist) as m FROM Auto_Parts  GROUP BY Car_id) b ON Auto_Parts.Car_id = b.Car_id
inner join Auto_Parts  on a.Job_Card = Auto_Parts.Job_Card
INNER JOIN Service_Type ON Auto_Parts.Servce_id = Service_Type.Servce_id

WHERE Auto_Parts.Current_dist > m - 3002 AND Auto_Parts.Car_id = 555
ORDER BY Change_date desc ,Current_dist DESC  


What I have tried:

this code is two table,table( auto_Part) have constant value ,table(Auto_Part_Details) is details for Car_id
Posted

1 solution

Add an alias for all references to the Auto_Parts table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900