MySQL 练习

Posted 萌新想吃鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 练习相关的知识,希望对你有一定的参考价值。

 1 USE DEMO;
 2 
 3 SELECT * FROM t_emp;
 4 
 5 SELECT empno,ename,sal FROM t_emp;
 6 
 7 SELECT empno,sal*12 AS "income" FROM t_emp;
 8 
 9 SELECT empno,ename FROM t_emp LIMIT 5,5;
10 
11 SELECT empno,ename,sal,deptno FROM t_emp ORDER BY sal DESC;
12 
13 SELECT empno,ename,sal,hiredate FROM t_emp ORDER BY hiredate ASC;
14 
15 SELECT empno,ename,sal,hiredate,deptno FROM t_emp ORDER BY deptno ASC,sal DESC;
16 
17 SELECT * FROM t_emp ORDER BY sal DESC LIMIT 0,5;
18 
19 SELECT DISTINCT job FROM t_emp;
20 
21 SELECT empno,ename,sal FROM t_emp WHERE deptno=10 AND sal>=2000; 
22 
23 SELECT empno,ename,sal,hiredate FROM t_emp
24 WHERE deptno=10 AND (sal+IFNULL(comm,0))*12>=15000 AND DATEDIFF(NOW(),hiredate)/365>=20;
25 
26 SELECT ename,deptno,hiredate,job FROM t_emp
27 WHERE deptno IN(10,20,30) AND hiredate<"1985-01-01" AND job!="SALESMAN";
28 
29 SELECT ename,comm,sal FROM t_emp
30 WHERE comm IS NOT NULL 
31 AND sal BETWEEN 1000 AND 3000
32 AND ename REGEXP "^[\u4e00-\u9fa5]{2,4}$";
33 
34 
35 SELECT ename,sal,deptno FROM t_emp
36 WHERE NOT deptno IN(10,20) XOR sal>2000
37 ;

总结,SQL语句查询的执行顺序, FROM -> WHERE -> SELECT -> ORDER BY -> LIMIT

以上是关于MySQL 练习的主要内容,如果未能解决你的问题,请参考以下文章

csharp Epicor标准练习片段

golang 去练习片段

部分代码片段

linux中怎么查看mysql数据库版本

ktor HTTP API 练习

从mysql的片段中加载ListView