我有这个mysql查询:
select `sc_documentos`.*, `sc_clientesproveedores`.`nombre` as `cliente`,
`sc_documentos`.`descripcion` as `desc`, SUM(sc_documentos.total) AS sumaTotal,
`sc_series`.`nombre` as `serie`
from `sc_documentos`
inner join `sc_clientesproveedores` on `sc_clientesproveedores`.`id` = `sc_documentos`.`idCliente`
inner join `sc_series` on `sc_series`.`id` = `sc_documentos`.`idSerie`
where (`sumaTotal` >= 100 and `sumaTotal` <= 200 and `tipo` like '%presupuesto%'
and `sc_documentos`.`idUsuario` = 1682)
and `sc_documentos`.`deleted_at` is null order by `sc_documentos`.`created_at` desc
Mysql说:SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ sumaTotal”
请帮忙,我认为我可以使用多个选择项,但不知道如何...
最佳答案
在您的查询中,sumaTotal
是SUM(sd_documentos.total)
的别名。因此,请使用HAVING sumaTotal >= 100 and sumaTotal <= 200
或WHERE SUM(sc_documentos.total) >= 100 AND SUM(sc_documentos.total) <= 200