简单查询
-- 查询林黛玉的电子邮箱和电话号码
select email , phone from users where username='林黛玉';
效果图:
计算每种性别的员工数量:
-- 计算每种性别的员工数量
select gender , count(*) from users group by gender;
效果图:
按照员工入职时间顺序进行查询:
-- 按照员工入职时间顺序进行查询
select * from users order by hire_date asc;
效果图:
复杂查询
员工和其对应职位信息:
-- 员工和其对应职位信息
select users.username,zhiwei.zhiwei from users
left join zhiwei on users.user_id = zhiwei.users_id;
效果图:
职位所对应部门信息:
-- 职位所对应部门信息
select zhiwei.zhiwei,bumen.bumen from zhiwei
right join bumen on bumen.zhiwei_id = zhiwei.zhiwei_id;
效果图:
子查询实例:
-- 通过子查询连接三个表
select * from users join bumen on users.user_id = bumen.users_id join (select * from zhiwei ) zh on users.user_id = zh .zhiwei_id;
效果图: