在具有内部连接的位置找不到列

Column not found in where with inner joins

我有这个 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 clause'

中的未知列 'sumaTotal'

请帮助我认为我可以使用多个 select o 一些,但不知道如何...

在您的查询中 sumaTotalSUM(sd_documentos.total) 的别名。所以要么使用 HAVING sumaTotal >= 100 and sumaTotal <= 200 要么 WHERE SUM(sc_documentos.total) >= 100 AND SUM(sc_documentos.total) <= 200

sumaTotal 是查询中 SUM 部分的别名,因此您可以这样更改查询:

select `sc_documentos`.*, `sc_clientesproveedores`.`nombre` as `cliente`,
`sc_documentos`.`descripcion` as `desc`,
`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`
HAVING  (SUM(sc_documentos.total) >= 100 and SUM(sc_documentos.total) <= 200 and `tipo` like '%presupuesto%'
and `sc_documentos`.`idUsuario` = 1682)
and `sc_documentos`.`deleted_at` is null order by `sc_documentos`.`created_at` desc

这在 simialbi 指令之后运行:(再次感谢)

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 (`tipo` like '%presupuesto%' and `sc_documentos`.`idUsuario` = 1682) and `sc_documentos`.`deleted_at` is null
group by `idCliente` having sumaTotal>=600 and sumaTotal<=800
order by `sc_documentos`.`created_at` desc