美文网首页
sql99的非等值连接和自连接

sql99的非等值连接和自连接

作者: dab7927433f9 | 来源:发表于2018-10-16 22:35 被阅读19次

    #(2)非等值连接

    #查询员工的工资级别

    SELECT salary,grade_level

    FROM employees e

    JOIN job_grades g

    ON e.salary BETWEEN g.lowest_sal AND g.highest_sal;

    #查询每个工资级别的个数>20的个数,并且按工资级别降序

    SELECT COUNT(*),grade_level

    FROM employees e

    JOIN job_grades g

    ON e.salary BETWEEN g.lowest_sal AND g.highest_sal

    GROUP BY grade_level

    HAVING COUNT(*)>20

    ORDER BY grade_level DESC;

    #(3)自连接

    #查询姓名中包含字符k的员工的名字、上级的名字

    SELECT e.last_name,m.last_name

    FROM employees e

    JOIN employees m

    ON e.`manager_id`=m.`employee_id`

    WHERE e.`last_name` LIKE '%k%';

    相关文章

      网友评论

          本文标题:sql99的非等值连接和自连接

          本文链接:https://www.haomeiwen.com/subject/zkvkzftx.html