MySQL,显示行和列之间的特定值

时间:2016-03-24 16:38:49

标签: mysql sql row identity-column

我有TABLE_1

  

emp_id | salary_step | salary_level
    1 | 13 | 4

现在,这里是TABLE_2:我想查询并获取以蓝色突出显示的值。我怎样才能做到这一点?非常感谢! (salary_grade和(1-8))

见图: TABLE_2

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT
    t1.*,
    CASE salary_level
        WHEN 1 THEN t2.`1`
        WHEN 2 THEN t2.`2`
        WHEN 3 THEN t2.`3`
        WHEN 4 THEN t2.`4`
    END AS LevelSalary
FROM TABLE_1 t1 INNER JOIN TABLE_2 t2 ON t1.salary_step = t2.salary_grade