组合范围内两个表的数据 - SQL

时间:2018-04-26 19:58:34

标签: sql

您好,我试图回答这个问题'我们的评估系统是否有助于培养员工。'目前我推荐的两个表是评估和员工,其中每个表都有评估分数(评估),promotion_last_5years(0/1)(员工)和满意度(员工)。 到目前为止,我有三个查询

  1. 4个评估分数中的员工输出数
  2. 每个职位的员工平均满意度
  3. 每个括号中提升的输出计数
  4. 1)

    SELECT e.range AS [0-1], count(*) AS [Number of Employees]
    FROM 
    (
      SELECT (CASE WHEN score BETWEEN 0 AND 0.25 THEN '0-0.25'
                   WHEN score BETWEEN 0.25 AND 0.5 THEN '0.25-0.5'
                   WHEN score BETWEEN 0.5 AND 0.75 THEN '0.5-0.75'
                   WHEN score BETWEEN 0.75 AND 1 THEN '0.75-1'
              END) as range
      FROM Evaluation
    ) e
    GROUP BY e.range;
    

    2)

    SELECT AVG(satisfaction)
    FROM Employee
    WHERE score IN (SELECT score FROM Evaluation WHERE score>0 AND score<0.25);
    

    3)

    SELECT promotion_last_5years, count(*) AS Proportion_promoted
    FROM Employee
    WHERE score IN (SELECT score FROM Evaluation WHERE score>0 AND score<0.25)
    GROUP BY promotion_last_5years;
    

    OR

    SELECT TotPromoted/TotalNotPromoted
    FROM 
    (
        SELECT count(*) AS TotPromoted 
        FROM Employee 
        WHERE promotion_last_5years='1' AND score IN 
        (
            SELECT score FROM Evaluations WHERE score>0 AND score<0.25
        );
    ),
    
    (SELECT count(*) AS TotalNotPromoted 
    FROM Employee 
    WHERE promotion_last_5years='0' AND score IN (SELECT score FROM Evaluations WHERE score>0 AND score<0.25);)
    

    依此类推剩余范围

    我问你有没有办法将这些查询中的数据合并到一个表中?如果是这样,请启发我,因为我是一个SQL初学者。此外,我对任何其他关于如何回答这个问题的建议持开放态度。提前谢谢!

0 个答案:

没有答案