首页 > 数据库 > MySQL > 正文

mysql 多表查询示例

2024-07-24 12:35:00
字体:
来源:转载
供稿:网友
  #案例:选中city在多伦多工作的员工
 
  SELECT
      last_name,job_id,e.department_id,department_name
  FROM
      employees AS e,departments AS d,locations AS l
  WHERE
      e.`department_id`=d.`department_id`
  AND
      d.`location_id`=l.`location_id`
  AND
      l.city='Toronto'
  #案例;查询每个国家下的部门个数大于2的国家编号
 
  SELECT
      country_id ,COUNT(*)
  FROM
      locations AS l,departments AS d
  WHERE
      l.`location_id`=d.`location_id`
 
  GROUP BY
      country_id
  HAVING
      COUNT(*) >2;

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表