开发者

MySql Group function error

select nume,model,sum(km_sosire-km_plecare) as 'km_parcursi' from masina m
inner join (foaie_parcurs f inner join angajat a using(id_angajat)) using(id_masina)
where sum(km_sosire-km_plecare)>100
group by a.nume,m.model
order by sum(km_sosire-km_plecare)开发者_开发技巧;

Error: Invalid use of group function

Why?

Thanks.


You can't use aggregates in the where clause. That's what "having" is for.

select nume,model,sum(km_sosire-km_plecare) as 'km_parcursi' from masina m
inner join (foaie_parcurs f inner join angajat a using(id_angajat)) using(id_masina)
group by a.nume,m.model
having sum(km_sosire-km_plecare)>100
order by sum(km_sosire-km_plecare);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜