SELECT COMO CLAUSULA NO WHERE
04/02/2019
0
Este é o Select que me mostra o valor da coluna do registro anterior, está executando certinho:
SELECT restcota FROM tbxerox x
order by xerox desc limit 1,1;
E este é o UPDATE, mas está emitindo erro : Error Code: 1093. You can't specify target table 'x' for update in FROM clause
UPDATE tbxerox x
INNER JOIN tbservidores s on s.cpfserv = x.cpf
set x.valor = (s.maxcot - s.total_xerox) * (-0.10)
where
(SELECT x.restcota
FROM tbxerox x
where x.cpf = x.cpf
order by x.xerox desc limit 1,1) > 0
and (x.restcota) < 0
and (s.maxcot - x.qtd_xerox) < 0
and (x.qtd_xerox) > 0
and (s.total_xerox) > 80
and x.xerox = ultimo_Xerox ()
and s.tiposerv = 'Professor';
Igor
Post mais votado
05/02/2019
UPDATE
tbxerox x INNER JOIN tbservidores s on s.cpfserv = x.cpf
set
x.valor = ((s.maxcot - s.total_xerox) * (-0.10))
where
( SELECT x1.restcota
FROM tbxerox x1
where x1.cpf = x1.cpf
order by x1.xerox desc limit 1,1) > 0
and (x.restcota) < 0
and (s.maxcot - x.qtd_xerox) < 0
and (x.qtd_xerox) > 0
and (s.total_xerox) > 80
and x.xerox = ultimo_Xerox ()
and s.tiposerv = 'Professor';
Kleber Santos
Mais Posts
05/02/2019
Igor
UPDATE
tbxerox x INNER JOIN tbservidores s on s.cpfserv = x.cpf
set
x.valor = ((s.maxcot - s.total_xerox) * (-0.10))
where
( SELECT x1.restcota
FROM tbxerox x1
where x1.cpf = x1.cpf
order by x1.xerox desc limit 1,1) > 0
and (x.restcota) < 0
and (s.maxcot - x.qtd_xerox) < 0
and (x.qtd_xerox) > 0
and (s.total_xerox) > 80
and x.xerox = ultimo_Xerox ()
and s.tiposerv = 'Professor';
Emitiu o mesmo erro
06/02/2019
Jorge Clésio
<br />
<br />
UPDATE <br />
tbxerox x INNER JOIN tbservidores s on s.cpfserv = x.cpf<br />
set <br />
x.valor = ((s.maxcot - s.total_xerox) * (-0.10))<br />
where<br />
( SELECT x1.restcota<br />
FROM tbxerox x1<br />
where x1.cpf = x1.cpf<br />
order by x1.xerox desc limit 1,1) > 0<br />
and (x.restcota) < 0<br />
and (s.maxcot - x.qtd_xerox) < 0<br />
and (x.qtd_xerox) > 0<br />
and (s.total_xerox) > 80<br />
and x.xerox = ultimo_Xerox ()<br />
and s.tiposerv = ''Professor'';
06/02/2019
Kleber Santos
Se certifique se essas colunas são do tipo numero:
"x.valor = ((s.maxcot - s.total_xerox) * (-0.10))"
Faça alguns testes, excluindo linha por linha do update até ele não apresentar mais o erro.
Poste as tabelas para a gente analisar.
06/02/2019
Kleber Santos
Esse SELECT está errado, não precisa do "where x.cpf = x.cpf"
E também não precisa do SELECT, pelo que está no código você precisa que o x.restcota seja diferente de 0
antes:
...( SELECT x1.restcota
FROM tbxerox x1
where x1.cpf = x1.cpf
order by x1.xerox desc limit 1,1) > 0
and (x.restcota) < 0...
depois:
...(x.restcota) <> 0...
Use assim:
UPDATE
tbxerox x INNER JOIN tbservidores s on s.cpfserv = x.cpf
set
x.valor = ((s.maxcot - s.total_xerox) * (-0.10))
where
(x.restcota) <> 0
and (s.maxcot - x.qtd_xerox) < 0
and (x.qtd_xerox) > 0
and (s.total_xerox) > 80
and x.xerox = ultimo_Xerox ()
and s.tiposerv = 'Professor';
06/02/2019
Igor
Esse SELECT está errado, não precisa do "where x.cpf = x.cpf"
E também não precisa do SELECT, pelo que está no código você precisa que o x.restcota seja diferente de 0
antes:
...( SELECT x1.restcota
FROM tbxerox x1
where x1.cpf = x1.cpf
order by x1.xerox desc limit 1,1) > 0
and (x.restcota) < 0...
depois:
...(x.restcota) <> 0...
Use assim:
UPDATE
tbxerox x INNER JOIN tbservidores s on s.cpfserv = x.cpf
set
x.valor = ((s.maxcot - s.total_xerox) * (-0.10))
where
(x.restcota) <> 0
and (s.maxcot - x.qtd_xerox) < 0
and (x.qtd_xerox) > 0
and (s.total_xerox) > 80
and x.xerox = ultimo_Xerox ()
and s.tiposerv = 'Professor';
Este é o Select que me mostra o valor da coluna do registro anterior. Preciso usar ele como critério pra atualizar o ultimo registro. Entendeu?
SELECT restcota FROM tbxerox x
order by xerox desc limit 1,1;
Clique aqui para fazer login e interagir na Comunidade :)