-----------------MYSQL练习题:数据查询(01)-增强版----------------------
提供了练习题目录以及答案,数据库内容在简易版;
简易版: https://blog.csdn.net/HIGK_365/article/details/128229258
- 说明:存放了数据库基础信息和练习题目录列表;
【答案】
SELECT name,sal FROM emp WHERE sal >= 3000;
【答案】
SELECT name,job FROM emp WHERE dept_id = 1;
【答案】
SELECT name,job FROM emp WHERE job <> "程序员";
SELECT name,job FROM emp WHERE job != "程序员";
【答案】
SELECT name,sal,job FROM emp WHERE comm = 300;
【答案】
SELECT * FROM emp WHERE dept_id = 1 AND sal > 2000;
【答案】
SELECT * FROM emp WHERE dept_id = 3 OR sal = 5000;
【答案】
SELECT name FROM emp WHERE job IN("CEO","项目经理");
【答案】
SELECT * FROM emp WHERE sal IN(3000,1500,5000);
【答案】
SELECT * FROM emp WHERE sal NOT IN(3000,1500,5000);
【答案】
SELECT * FROM emp WHERE sal BETWEEN 1000 AND 2000;
【答案】
SELECT * FROM emp WHERE sal NOT BETWEEN 1000 AND 2000;
【答案】
SELECT name,manager FROM emp WHERE manager IS NOT NULL;
【答案】
SELECT name,dept_id FROM emp WHERE manager IS NULL;
【答案】
SELECT job FROM emp GROUP BY job;
【答案】
SELECT dept_id FROM emp GROUP BY dept_id;
【答案】
SELECT name FROM emp WHERE name LIKE "孙%";
【答案】
SELECT * FROM emp WHERE name LIKE "%精";
【答案】
SELECT * FROM emp WHERE job LIKE "%销售%";
【答案】
SELECT * FROM emp WHERE job LIKE "_售";
【答案】
SELECT * FROM emp WHERE name LIKE "%僧%" AND sal > 2000;
【答案】
SELECT * FROM emp WHERE dept_id IN(1,2) AND job LIKE "市%";
【答案】
SELECT name,sal FROM emp ORDER BY sal;
【答案】
SELECT name,sal FROM emp ORDER BY sal DESC;
【答案】
SELECT name,sal,dept_id FROM emp ORDER BY dept_id desc,sal;
【答案】
SELECT * FROM emp WHERE dept_id = 3 AND sal > 1500;
【答案】
SELECT * FROM emp WHERE dept_id = 2 OR manager IS NULL;
【答案】
SELECT name,sal FROM emp WHERE manager IS NOT NULL ORDER BY SAL DESC;
hiredate
),并按照入职日期降序排序;【答案】
SELECT name,hiredate FROM emp WHERE dept_id IN(2,3) ORDER BY hiredate DESC;
【答案】
SELECT name FROM emp WHERE name LIKE "%僧%" OR name LIKE "%精%";
【答案】
SELECT job FROM emp GROUP BY job HAVING max(sal) > 2000;
SELECT job FROM emp WHERE sal > 2000 GROUP BY job;
【答案】
SELECT * FROM emp ORDER BY sal DESC LIMIT 0,3;
【答案】
SELECT * FROM emp ORDER BY id LIMIT 5,5;
【答案】
SELECT * FROM emp ORDER BY id LIMIT 8,4;
【答案】
SELECT name,sal FROM emp WHERE dept_id = 3 AND sal = ( SELECT MIN(sal) FROM emp WHERE dept_id = 3 );
【答案】
SELECT * FROM emp WHERE job != "人事" ORDER BY sal DESC LIMIT 3,3;
【答案】
SELECT name,sal,sal*5 FROM emp;
【答案】
不属于数据查询范畴,略 有专门的增删改练习题集
【答案】
SELECT * FROM emp WHERE manager IS NULL OR dept_id = 3 ORDER BY sal DESC LIMIT 0,3;
【答案】
SELECT MAX(sal) FROM emp WHERE dept_id = 2;
【答案】
SELECT COUNT(*) FROM emp WHERE manager IS NOT NULL AND sal BETWEEN 1000 AND 2000;
【答案】
SELECT SUM(sal) FROM emp WHERE dept_id = 3;
【答案】
SELECT COUNT(*) FROM emp WHERE job IN("程序员","销售");
【答案】
SELECT AVG(sal) FROM emp WHERE dept_id = 1 AND manager IS NOT NULL;
【答案】
SELECT MIN(sal), MAX(sal) FROM emp WHERE dept_id = 1;
【答案】
SELECT COUNT(*) FROM emp WHERE job LIKE "%销售%";
【答案】
SELECT COUNT(*) FROM emp WHERE sal NOT IN(1500,3000);
【答案】
SELECT job FROM emp WHERE dept_id = 1 GROUP BY job;
【答案】
SELECT COUNT(*) FROM emp WHERE name LIKE "%精%";
【答案】
SELECT SUM(sal) FROM emp WHERE job LIKE "%销售%";
【答案】
SELECT MAX(sal) top,MIN(sal) bottom FROM emp WHERE dept_id = 2;
【答案】
SELECT dept_id,AVG(sal) FROM emp GROUP BY dept_id;
【答案】
SELECT job,AVG(sal) FROM emp GROUP BY job;
【答案】
SELECT dept_id,MAX(sal) FROM emp GROUP BY dept_id;
【答案】
SELECT job,MIN(sal) FROM emp GROUP BY job;
【答案】
SELECT dept_id,COUNT(*) FROM emp WHERE sal >2000 GROUP BY dept_id;
【答案】
SELECT dept_id,COUNT(*) FROM emp WHERE manager IS NOT NULL GROUP BY dept_id;
【答案】
SELECT job,MIN(sal) FROM emp WHERE dept_id = 1 GROUP BY job;
【答案】
SELECT dept_id,AVG(sal) FROM emp GROUP BY dept_id ORDER BY AVG(sal) DESC LIMIT 0,1;
【答案】
SELECT dept_id,AVG(sal) FROM emp GROUP BY dept_id HAVING AVG(sal) > 2000;
【答案】
SELECT job,COUNT(*) FROM emp GROUP BY job HAVING COUNT(*) > 1;
【答案】
SELECT dept_id,SUM(sal) FROM emp WHERE manager IS NOT NULL GROUP BY dept_id HAVING SUM(sal) > 5400;
【答案】
SELECT dept_id,AVG(sal) FROM emp WHERE sal BETWEEN 1000 AND 3000 GROUP BY dept_id HAVING AVG(sal) > 2000;
【答案】
SELECT * FROM emp WHERE sal > ( SELECT AVG(sal) FROM emp WHERE dept_id = 2 );
【答案】
SELECT * FROM emp WHERE sal > ( SELECT MAX(sal) FROM emp WHERE job = "程序员" );
【答案】
SELECT * FROM emp ORDER BY sal DESC LIMIT 0,1;
【答案】
SELECT * FROM dept WHERE id = ( SELECT dept_id FROM emp WHERE name = "孙悟空" );
【答案】
SELECT * FROM emp WHERE job = ( SELECT job FROM emp WHERE name="孙悟空" ) AND name != "孙悟空";
【答案】
SELECT * FROM emp WHERE dept_id = ( SELECT dept_id FROM emp WHERE sal= ( SELECT MIN(sal) FROM emp ) ) AND sal != ( SELECT MIN(sal) FROM emp );
SELECT * FROM emp WHERE dept_id = ( SELECT dept_id FROM emp ORDER BY sal LIMIT 0,1 ) AND sal != ( SELECT sal FROM emp ORDER BY sal LIMIT 0,1 );