heidisql - SQL count and sum query -
i have query shows model,brand , category of equipment , engineer installed equipment,the commission earned doing job , county equipment installed. used query display distinct models installed engineers if engineer installed same equipment in county display equipment once county same equipment displayed again if engineer installed in county. query:
select distinct models.model,brands.brand, categories.name, equipments.commission, equipments.engineer_name, counties.name equipments inner join models on equipments.model = models.id inner join brands on equipments.brand = brands.id inner join categories on equipments.category = categories.id inner join agencies on equipments.agency = agencies.id inner join counties on agencies.county = counties.id inner join clients on agencies.client = clients.id equipments.engineer!='all' order counties.name asc,equipments.engineer_name
i want use count display how many times equipment installed same engineer in county , use sum calculate commission(fee) gets installing same equipment "n" number of times. eg: have "g" brand, model "y", category "z", commission 2 , installed in same county same engineer 5 times. case should display: g, y, z, 2, equipments.engineer_name,counties.name, 5,10( because 5*2=10)
i tried use count(distinct models.model) doesn't work
Comments
Post a Comment