简体   繁体   中英

Error Code: 1241. Operand should contain 1 column(s) On Updates and Trigger

I Have a soccer database, and I have a trigger (notas) that is calculating a player rating after the insert of his stats, I am able to create the trigger, but when I update the player stats it gives me Error Code: 1241

(My update is in Table JogadoresEstatísticasBrutas, but is because there is other trigger working, and that trigger insert stats on Table JogadoresEstatísticasPorJogo, After some tests I discovered that the problem is in Trigger Notas.)

DELIMITER //
CREATE TRIGGER Notas 
AFTER UPDATE ON JogadoresEstatísticasPorJogo 
FOR EACH ROW
begin
set @Nome = new.Nome;
set @GolsPJN = new.GolsPJ;
set @AstPJN = new.AssistsPJ;
set @PreAstPJN = new.PréAstPJ;
set @GrandesChancesCriadasPJN = new.GrandesChancesCriadasPJ;
set @GrandesChancesErradasPJN = new.GrandesChancesErradasPJ;
set @PassesTentadosPJN = new.PassesTentadosPJ;
set @PassesCompletosPJN = new.PassesCompletosPJ;
set @PorcentagemPassesPJN = new.PorcentagemPassesPJ;
set @DriblesTentadosPJN = new.DriblesTentadosPJ;
set @DriblesCompletosPJN = new.DriblesCompletosPJ;
set @ChutesTentadosPJN = new.ChutesTentadosPJ;
set @ChutesNoGolPJN = new.ChutesNoGolPJ;
set @ChutesBloqueadosPJN = new.ChutesBloqueadosPJ;
set @PerdadePossePJN = new.PerdadePossePJ;
set @DesarmesCompletosPJN = new.DesarmesCompletosPJ;
set @TentativasSofridasdeDriblePJN = new.TentativasSofridasdeDriblePJ;
set @DriblesSofridosPJN = new.DriblesSofridosPJ;
set @BloqueiosPJN = new.BloqueiosPJ;
set @InterceptacoesPJN = new.InterceptaçõesPJ;
set @DuelosAereosGanhosPJN = new.DuelosAéreosGanhosPJ;
set @DuelosAereosPerdidosPJN = new.DuelosAéreosPerdidosPJ;
set @FaltasCometidasPJN = new.FaltasCometidasPJ;

set @GolsNotas = @GolsPJN * 25;
set @GrandesChancesErradasNotas = (@GolsPJN - @GrandesChancesErradasPJN) * 17;
set @DriblesNotas = @DriblesCompletosPJN / @DriblesTentadosPJN * 2;
set @ChutesNotas = @ChutesnoGolPJN / @ChutesTentadosPJN * 15;
set @PerdadePosseNotas = @PerdadePossePJN / (@PassesTentadosPJN + @DriblesTentadosPJN) * (-65);

set @AstNotas = @AstPJN * 25;
set @PreAst = @PreAstPJN * 50;
set @GrandesChancesCriadas = @GrandesChancesCriadasPJN / @PassesCompletosPJN * 60;
set @PorcentagemNotas = @PorcentagemPassesPJN / 10 * 1.50;

set @DesarmesNotas = @DesarmesCompletosPJN * 25;
set @DriblesSofridosNotas = (10 - (@DriblesSofridosPJN / @TentativasSofridasdeDriblePJN * 3,5)) *2;
set @FaltasCometidasNotas = @FaltasCometidasPJN * (-8);
set @BloqueiosInterceptacoesNotas = (@BloqueiosPJN * 2 + @InterceptacoesPJN * 7) *3;

set @NotaOfensiva = truncate ((@GolsNotas + @GrandesChancesErradasNotas + DriblesNotas + ChutesNotas + PerdadePosseNotas) / 10 , 2);
set @NotaCriacao = truncate ((@AstNotas + @PreAst + @GrandesChancesCriadas + @PorcentagemNotas) / 10, 2);
set @NotaDefensiva = truncate ((@DesarmesNotas + @DriblesSofridosNotas + @FaltasCometidasNotas + @BloqueiosInterceptacoesNotas) / 10 , 2);

set @NotaGeral = (@NotaOfensiva + @NotaCriacao + @NotaDefensiva) / 3;


update JogadoresNotas set NotaOfensiva = @NotaOfensiva where Nome = @Nome;
update JogadoresNotas set NotaCriação = @NotaCriacao where Nome = @Nome;
update JogadoresNotas set NotaDefensiva = @NotaDefensiva where Nome = @Nome;
update JogadoresNotas set NotaGeral = @NotaGeral where Nome = @Nome;
end //
DELIMITER ;

My Updates:

DELIMITER // begin
Update JogadoresEstatísticasBrutas SET Nome = 'R', Jogos = "7", Gols = "3", Assists = "5", PréAst = "0", GrandesChancesCriadas = "10", GrandesChancesErradas = "4", PassesTentados = "65", PassesCompletos = "55", PorcentagemPasses = "84", DriblesTentados = "18", DriblesCompletos = "11", ChutesTentados = "7", ChutesNoGol = "5", ChutesBloqueados = "1", PerdadePosse = "13", DesarmesCompletos = "6", TentativasSofridasdeDrible = "8", DriblesSofridos = "4", Bloqueios = "10", Interceptações = "4", DuelosAéreosGanhos = "1", DuelosAéreosPerdidos = "0", FaltasCometidas = "2", FaltasSofridas = "2", ChutesSofridos = "6", Defesas = "3", ChutesDifíceis = "3", DefesasDifíceis = "0" where Nome = "R";
Update JogadoresEstatísticasBrutas SET Nome = 'N', Jogos = "7", Gols = "3", Assists = "2", PréAst = "1", GrandesChancesCriadas = "5", GrandesChancesErradas = "4", PassesTentados = "37", PassesCompletos = "29", PorcentagemPasses = "78", DriblesTentados = "12", DriblesCompletos = "6", ChutesTentados = "10", ChutesNoGol = "5", ChutesBloqueados = "0", PerdadePosse = "8", DesarmesCompletos = "3", TentativasSofridasdeDrible = "11", DriblesSofridos = "7", Bloqueios = "3", Interceptações = "0", DuelosAéreosGanhos = "1", DuelosAéreosPerdidos = "0", FaltasCometidas = "4", FaltasSofridas = "2", ChutesSofridos = "9", Defesas = "7", ChutesDifíceis = "2", DefesasDifíceis = "1" where Nome = "N";
Update JogadoresEstatísticasBrutas SET Nome = 'B', Jogos = "7", Gols = "6", Assists = "3", PréAst = "1", GrandesChancesCriadas = "4", GrandesChancesErradas = "6", PassesTentados = "54", PassesCompletos = "48", PorcentagemPasses = "88", DriblesTentados = "22", DriblesCompletos = "14", ChutesTentados = "25", ChutesNoGol = "10", ChutesBloqueados = "7", PerdadePosse = "14", DesarmesCompletos = "7", TentativasSofridasdeDrible = "10", DriblesSofridos = "6", Bloqueios = "4", Interceptações = "5", DuelosAéreosGanhos = "0", DuelosAéreosPerdidos = "3", FaltasCometidas = "4", FaltasSofridas = "4", ChutesSofridos = "7", Defesas = "4", ChutesDifíceis = "5", DefesasDifíceis = "2" where Nome = "B";
Update JogadoresEstatísticasBrutas SET Nome = 'F', Jogos = "7", Gols = "8", Assists = "1", PréAst = "1", GrandesChancesCriadas = "6", GrandesChancesErradas = "3", PassesTentados = "55", PassesCompletos = "40", PorcentagemPasses = "72", DriblesTentados = "18", DriblesCompletos = "10", ChutesTentados = "17", ChutesNoGol = "7", ChutesBloqueados = "4", PerdadePosse = "10", DesarmesCompletos = "9", TentativasSofridasdeDrible = "19", DriblesSofridos = "7", Bloqueios = "14", Interceptações = "3", DuelosAéreosGanhos = "0", DuelosAéreosPerdidos = "0", FaltasCometidas = "2", FaltasSofridas = "3", ChutesSofridos = "13", Defesas = "9", ChutesDifíceis = "7", DefesasDifíceis = "3" where Nome = "F";
Update JogadoresEstatísticasBrutas SET Nome = 'G', Jogos = "7", Gols = "9", Assists = "1", PréAst = "1", GrandesChancesCriadas = "6", GrandesChancesErradas = "5", PassesTentados = "52", PassesCompletos = "44", PorcentagemPasses = "84", DriblesTentados = "8", DriblesCompletos = "1", ChutesTentados = "29", ChutesNoGol = "21", ChutesBloqueados = "6", PerdadePosse = "11", DesarmesCompletos = "5", TentativasSofridasdeDrible = "15", DriblesSofridos = "9", Bloqueios = "9", Interceptações = "5", DuelosAéreosGanhos = "1", DuelosAéreosPerdidos = "0", FaltasCometidas = "0", FaltasSofridas = "2", ChutesSofridos = "5", Defesas = "2", ChutesDifíceis = "3", DefesasDifíceis = "1" where Nome = "G";
Update JogadoresEstatísticasBrutas SET Nome = 'D', Jogos = "7", Gols = "4", Assists = "0", PréAst = "1", GrandesChancesCriadas = "6", GrandesChancesErradas = "7", PassesTentados = "55", PassesCompletos = "51", PorcentagemPasses = "92", DriblesTentados = "12", DriblesCompletos = "6", ChutesTentados = "19", ChutesNoGol = "13", ChutesBloqueados = "4", PerdadePosse = "10", DesarmesCompletos = "9", TentativasSofridasdeDrible = "22", DriblesSofridos = "12", Bloqueios = "8", Interceptações = "1", DuelosAéreosGanhos = "0", DuelosAéreosPerdidos = "0", FaltasCometidas = "3", FaltasSofridas = "0", ChutesSofridos = "3", Defesas = "1", ChutesDifíceis = "2", DefesasDifíceis = "1" where Nome = "D";
end; DELIMITER;

Tables JogadoresEstatísticasBrutas and JogadoresNotas

CREATE TABLE IF NOT EXISTS JogadoresEstatísticasBrutas (
IdJogadores INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  Nome VARCHAR(40) NULL,
  Jogos INT NULL,
  Gols INT NULL,
  Assists INT NULL,
  PréAst INT NULL,
  GrandesChancesCriadas INT NULL,
  GrandesChancesErradas INT NULL,
  PassesTentados INT NULL,
  PassesCompletos INT NULL,
  PorcentagemPasses INT NULL,
  DriblesTentados INT NULL,
  DriblesCompletos INT NULL,
  ChutesTentados INT NULL,
  ChutesNoGol INT NULL,
  ChutesBloqueados INT NULL,
  PerdadePosse INT NULL,
  DesarmesCompletos INT NULL,
  TentativasSofridasdeDrible INT NULL,
  DriblesSofridos INT NULL,
  Bloqueios INT NULL,
  Interceptações INT NULL,
  DuelosAéreosGanhos INT NULL,
  DuelosAéreosPerdidos INT NULL,
  FaltasCometidas INT NULL,
  FaltasSofridas INT NULL,
  ChutesSofridos INT NULL,
  Defesas INT NULL,
  ChutesDifíceis INT NULL,
  DefesasDifíceis INT NULL);

CREATE TABLE IF NOT EXISTS JogadoresNotas (
  IdJogadores INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  Nome VARCHAR(40) NULL,
  Jogos INT NULL,
  NotaOfensiva FLOAT (3, 2) NULL,
  NotaCriação FLOAT (3, 2) NULL,
  NotaDefesinva FLOAT (3, 2) NULL,
  NotaGeral FLOAT (4, 2) NULL);

Per reference manual , you can use set to change multiple values that are , separated.

CREATE TRIGGER Notas 
AFTER UPDATE ON JogadoresEstatísticasPorJogo 
FOR EACH ROW
set @Nome = new.Nome,
    @GolsPJN = new.GolsPJ,
    @AstPJN = new.AssistsPJ,
    ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM