MySQL中关联查询相关语句
Posted feixiangdecainiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL中关联查询相关语句相关的知识,希望对你有一定的参考价值。
-- emp和job查询 SELECT t1.`id`, t1.`ename`, t1.`salary`, t2.`jname`, t2.`descriptions` FROM emp t1,job t2,dept t3 WHERE t1.`job_id`=t2.`id`AND t3.`id`=t1.`dept_id`; -- 查询工资的等级 SELECT t1.ename,t1.`salary`,t2.`grade` FROM emp t1,salarygrade t2 WHERE t1.`salary`BETWEEN t2.`hisalar`AND t2.`hisalar`; SELECT t1.`id`,t1.`dname`,t1.`loc`,t2.total FROM dept t1, (SELECT dept_id,COUNT(id) total FROM emp GROUP BY emp.`dept_id`) t2 WHERE t1.`id`=t2.dept_id; SELECT t1.`ename`, t1.`mgr`, t2.`id`, t2.`ename` FROM emp t1,emp t2 WHERE t1.`id`=t2.`mgr`; SELECT t1.`ename`, t1.`mgr`, t2.`id`, t2.`ename` FROM emp t1 LEFT JOIN emp t2 ON t1.`mgr`=t2.`id`
以上是关于MySQL中关联查询相关语句的主要内容,如果未能解决你的问题,请参考以下文章