Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
How can I update my database table with the result of my query

I am a French designer and I have a SQL problem. My MySQL server is in v5.6 and i ask for help because I have a syntax problem. I think you can bring me a solution.

I have a data base called "scores":

id pseudo tempsstage1mili rangstage1
1 pseudo1 20100 ---
2 pseudo2 16900 ---

and I ask this to MySQL :

SELECT pseudo,
 @curRank := @curRank + 1 AS rank
FROM scores p, (SELECT @curRank := 0) r
ORDER BY  tempsstage1mili;

With this command, MySQL return this :

pseudo rank
pseudo2 1
pseudo1 2

At this step it's perfect but now, I want to Update my table called "scores" with the result. The column I have to Update is called "rangstage1" with the column "rank"

I want to get that :

id pseudo tempsstage1mili rangstage1
1 pseudo1 20100 2
2 pseudo2 16900 1

Could you help me ? Please ? You are hope !

Thank you !

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can turn this into an update:

SET @curRank = 0;

UPDATE scores
    SET rankstage1 = (@curRank := @curRank + 1)
    ORDER BY tempsstage1mili;
over 4 years ago · Santiago Trujillo Relatório

0

After some tries I think this will help:

UPDATE scores s
INNER JOIN 
( select i.pseudo, i.rank from (SELECT pseudo,
@curRank := @curRank + 1 AS rank
FROM scores p, (SELECT @curRank := 0) r
ORDER BY  tempsstage1mili ) i ) a
ON s.pseudo = a.pseudo
SET s.rangstage1 = a.rank ;

Please try and give me feedback, is it working ?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda