Mysql sub-base 1

Asked

Viewed 80 times

-1

Motta,

Thanks for the agility, but this instruction is showing only the highest salary. I tried the INNER JOINT, and almost got it. Imagine that I want to compare the salary of people with the same position. See if you can understand with the attached image.

Exemplo

Friends,

I would like your help in Mysql, I have a table of employees that has only three columns, NAME, POSITION and SALARY, I want to set up a query that brings me all this table and contains in it the highest salary value for the position. Totaling 4 columns (NAME, POSITION, SALARY AND MAIOR_SALARIO_P_CARGO. This is to check the variation.

  • 1

    Welcome to the site! Please edit your original question with the additional information instead of creating a new question or trying to edit one of the answers. This will possibly be closed as duplicate, but do not worry that this is just a matter of organizing the site. Over time you get the hang of :)

  • 1

    You can also remove this "question", since it is not really a question.

1 answer

1

Hello, I believe that this query can solve, I did not test it.

SELECT
    T1.NOME,
    T1.CARGO,
    T1.SALARIO_ATUAL,
    (
        SELECT MAX(SALARIO_ATUAL)
        FROM TABELA T2
        WHERE T2.CARGO = T1.CARGO
    ) AS MAIOR_SALARIO_PARA_CARGO
FROM TABELA T1
  • 1

    Alan, it worked perfectly...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.