当前位置:网站首页>Mysql database, query
Mysql database, query
2022-07-24 02:30:00 【The end of the world and you】
Mysql database , Inquiry section
1. Sample table contents
dept surface :
+--------+------------+----------+
| DEPTNO | DNAME | LOC |
+--------+------------+----------+
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
emp surface :
+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
salgrade surface :
+-------+-------+-------+
| GRADE | LOSAL | HISAL |
+-------+-------+-------+
| 1 | 700 | 1200 |
| 2 | 1201 | 1400 |
| 3 | 1401 | 2000 |
| 4 | 2001 | 3000 |
| 5 | 3001 | 9999 |
+-------+-------+-------+
2. Simple query
MySQL Database usage SQL SELECT Statement to query data .
For example, we want to query all the information of a table , You can do this :
Of course , This way of querying is inefficient , We recommend you to use multi column query :
mysql> select * from dept;
+--------+------------+----------+
| DEPTNO | DNAME | LOC |
+--------+------------+----------+
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
4 rows in set (0.00 sec)
that , If you want to query the information of a single column ?
You can specify the column name to query :
mysql> select DNAME from dept;
+------------+
| DNAME |
+------------+
| ACCOUNTING |
| RESEARCH |
| SALES |
| OPERATIONS |
+------------+
4 rows in set (0.00 sec)
Query the information of multiple columns , It can be written like this :
mysql> select DNAME , LOC from dept;
+------------+----------+
| DNAME | LOC |
+------------+----------+
| ACCOUNTING | NEW YORK |
| RESEARCH | DALLAS |
| SALES | CHICAGO |
| OPERATIONS | BOSTON |
+------------+----------+
4 rows in set (0.00 sec)
3. Alias the list
During the query , We can also choose to list an alias :
mysql> select DNAME as NAME from dept;
+------------+
| NAME |
+------------+
| ACCOUNTING |
| RESEARCH |
| SALES |
| OPERATIONS |
+------------+
4 rows in set (0.00 sec)
Or you can skip it as keyword :
mysql> select DNAME NAME from dept;
+------------+
| NAME |
+------------+
| ACCOUNTING |
| RESEARCH |
| SALES |
| OPERATIONS |
+------------+
4 rows in set (0.00 sec)
In all databases , Single quotation marks are used for strings , It's a standard 🧨
4. Column operation
At query time , We can also directly perform column operations :
such as , We want to calculate the annual salary of our employees :
mysql> select ename,sal*12 from emp;
+--------+----------+
| ename | sal*12 |
+--------+----------+
| SMITH | 9600.00 |
| ALLEN | 19200.00 |
| WARD | 15000.00 |
| JONES | 35700.00 |
| MARTIN | 15000.00 |
| BLAKE | 34200.00 |
| CLARK | 29400.00 |
| SCOTT | 36000.00 |
| KING | 60000.00 |
| TURNER | 18000.00 |
| ADAMS | 13200.00 |
| JAMES | 11400.00 |
| FORD | 36000.00 |
| MILLER | 15600.00 |
+--------+----------+
14 rows in set (0.00 sec)
5. Conditions of the query
Example 1: The query salary is greater than or equal to 3000 Information about :
mysql> select empno,ename from emp where sal >= 3000;
+-------+-------+
| empno | ename |
+-------+-------+
| 7788 | SCOTT |
| 7839 | KING |
| 7902 | FORD |
+-------+-------+
3 rows in set (0.00 sec)
Example 2: Check salary at 2000 To 3000( contain 2000 and 3000) Information about :
mysql> select empno,ename from emp where sal between 2000 and 3000;
+-------+-------+
| empno | ename |
+-------+-------+
| 7566 | JONES |
| 7698 | BLAKE |
| 7782 | CLARK |
| 7788 | SCOTT |
| 7902 | FORD |
+-------+-------+
5 rows in set (0.00 sec)
Example 3: Query employees whose subsidies are empty ( Not empty is not null):
mysql> select empno,ename from emp where comm is null;
+-------+--------+
| empno | ename |
+-------+--------+
| 7369 | SMITH |
| 7566 | JONES |
| 7698 | BLAKE |
| 7782 | CLARK |
| 7788 | SCOTT |
| 7839 | KING |
| 7876 | ADAMS |
| 7900 | JAMES |
| 7902 | FORD |
| 7934 | MILLER |
+-------+--------+
10 rows in set (0.00 sec)
Mysql Compare NULL Value cannot be used
=Number
Example 4: Query position is MANAGER And the salary is greater than or equal to 2500 Information about :
mysql> select * from emp where JOB = "MANAGER" and SAL >= 2500;
+-------+-------+---------+------+------------+---------+------+--------+
| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
+-------+-------+---------+------+------------+---------+------+--------+
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
+-------+-------+---------+------+------------+---------+------+--------+
2 rows in set (0.00 sec)
Example 5: Query position is MANAGER perhaps SALESMAN The employees' :( Use keywords in)( Do not use between certain values not in)
mysql> select empno,ename,job from emp where job in ('MANAGER','SALESMAN');
+-------+--------+----------+
| empno | ename | job |
+-------+--------+----------+
| 7499 | ALLEN | SALESMAN |
| 7521 | WARD | SALESMAN |
| 7566 | JONES | MANAGER |
| 7654 | MARTIN | SALESMAN |
| 7698 | BLAKE | MANAGER |
| 7782 | CLARK | MANAGER |
| 7844 | TURNER | SALESMAN |
+-------+--------+----------+
7 rows in set (0.00 sec)
Example 6: Fuzzy query , Find the letters in the name o Of :
mysql> select ename from emp where ename like '%o%';
+-------+
| ename |
+-------+
| JONES |
| SCOTT |
| FORD |
+-------+
3 rows in set (0.00 sec)
Example 7: Fuzzy query , Find the name to T At the end of the :
mysql> select ename from emp where ename like '%T';
+-------+
| ename |
+-------+
| SCOTT |
+-------+
1 row in set (0.00 sec)
Example 8: Fuzzy query , Find the name to K At the beginning :
mysql> select ename from emp where ename like 'K%';
+-------+
| ename |
+-------+
| KING |
+-------+
1 row in set (0.00 sec)
Example 9: Fuzzy query , Find out that the second letter of the name is A Of :
mysql> select ename from emp where ename like '_A%';
+--------+
| ename |
+--------+
| WARD |
| MARTIN |
| JAMES |
+--------+
3 rows in set (0.00 sec)
Example 10: Fuzzy query , Find out that the third letter of the name is A Of :
mysql> select ename from emp where ename like '__A%';
+-------+
| ename |
+-------+
| BLAKE |
| CLARK |
| ADAMS |
+-------+
3 rows in set (0.00 sec)
边栏推荐
- redis数据类型概念
- Opensmile introduction and problems encountered during installation
- Network protocol details: TCP part1
- Writing of graph nodes that trigger different special effects during the day and at night in Tiktok
- Combined with actual combat, analyze gb/t 28181 (II) -- equipment directory synchronization
- Causal learning open source project: from prediction to decision!
- Research on XMPP service (I)
- The new red envelope cover platform can build the source code of the independent background of the sub station
- Sharing a case of controller restart caused by a CIFS bug in NetApp Fas series
- 2022-07-22: what is the output of the following go language code? A:1; B:1.5; C: Compilation error; D:1.49。 package main import “fmt“ func main() { var i
猜你喜欢

Chinese scientists have made new progress in high security quantum key distribution networks

Wallys/DR4019S/IPQ4019/11ABGN/802.11AC/high power

In depth understanding - wechat developer tools

Causal learning open source project: from prediction to decision!

How to do a good job of accompanying translation

利用宝塔面板计划任务执行自动推送网址到百度收录

7 issues to consider before website construction

Share an API Gateway project based on ABP and yarp

Wallys/PD-60 802.3AT Input Output802.3AT/AT 85% Efficiency 10/100/1000M GE Surge Protection

Digital transformation behind the reshaping growth of catering chain stores
随机推荐
“我们为什么要做 iVX ? ” ——访 iVX CEO 孟智平 了解 iVX 企业文化
Seatunnel architecture
Réalisation d'un diagramme de zone de ligne brisée - Diagramme Rose - Diagramme à barres
1000 okaleido tiger launched binance NFT, triggering a rush to buy
redis数据类型概念
5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字
[diary of supplementary questions] [2022 Niuke summer school 1] i-chiitoitsu
Understand the transport layer protocol - tcp/udp
認識傳輸層協議—TCP/UDP
[diary of supplementary questions] [2022 Hangdian summer school 1] c-backpack
Responsive layout a web page displays different effects on different devices) meta:vp
JDBC tool class
Installation, configuration and use of sentry
Essential skills for programmers -- breakpoint debugging (idea version)
Is software testing still popular in 2022?
关于 SAP Fiori 应用的离线使用
【补题日记】[2022杭电暑期多校1]B-Dragon slayer
Data conversion problem in Qt development serial communication software: when reading_ Qbytearray to string; When sending_ Data format; Int to hexadecimal format string; Intercept characters in string
输入cnpm -v出现cnpm : 无法加载文件 C:\Users\19457\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。
[jailhouse article] virtualization over multiprocessor system on chip an enabling paradigm for