当前位置:网站首页>MySQL - database query - basic query
MySQL - database query - basic query
2022-07-03 01:20:00 【Sauerkraut】
The basic query
MySQL Database usage SELECT Statement to query data .
1. Query multiple fields
The following is in MySQL A common way to query data in a database SELECT grammar :
SELECT Field name , Field name ... FROM Table name ;
SELECT * FROM Table name ; # Query all fields You can use one or more tables in a query statement , Use commas between tables (,) Division , And use WHERE Statement to set the query conditions .
SELECT Command can read one or more records .
You can use an asterisk (*) To replace other fields ,SELECT Statement will return all the field data of the table
2. Set alias
SELECT Field 1 [AS Alias ], Field 2 [AS Alias ]... FROM Table name ;3. Remove duplicate records
SELECT DISTINCT Field list FROM Table name ;4. Four arithmetic queries

Query requirement


Check the file code 
How to get there Navicat Import inside sql Data? ?

Start query operation

1. Query the specified field ename,job,sal The data of
SELECT ename,job,sal FROM emp;
2. Query all fields
SELECT empno,ename,job,mgr,hiredate,comm,deptno FROM emp;
Or use the following method to query all fields
① Not intuitive enough , You can't tell which fields there are at a glance
② Affect the efficiency of execution , First, go to the table to find which fields , And then check it out , There is one more step to find
-- Direct use is not recommended * --
SELECT * FROM emp;
3. Query all positions of employees , And name it
SELECT ename,job FROM emp;
names
SELECT ename,job AS ' jobs ' FROM emp;
AS It can be omitted
SELECT ename,job ' jobs ' FROM emp;
4. Query the positions of employees ( Don't repeat )
SELECT job FROM emp;Pay attention to the repetition , You need to display only one repetition

Use DISTINCT Keyword de duplication
SELECT DISTINCT job FROM emp;
If there are multiple fields , Can't get rid of the duplicate , This is the de duplication of a single field

5. Check the annual salary of employees namely sal * 12
SELECT ename,sal AS ' a monthly salary ',sal * 12 AS ' Annual salary ' FROM emp;
SELECT sal / 10 FROM emp;
SELECT sal DIV 10 FROM emp;

边栏推荐
- leetcode 2097 — 合法重新排列数对
- Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
- Niu Ke swipes questions and clocks in
- [day 29] given an integer, please find its factor number
- Create your first Kivy program Hello word (tutorial includes source code)
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- 机器学习术语
- [shutter] image component (cached_network_image network image caching plug-in)
- [self management] time, energy and habit management
- MySQL foundation 04 MySQL architecture
猜你喜欢

【无标题】

Arduino DY-SV17F自动语音播报

Linear programming of mathematical modeling (including Matlab code)

leetcode:701. 二叉搜索树中的插入操作【bst的插入】

leetcode 2097 — 合法重新排列数对
![1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]](/img/bf/ab6838e34a3074130eac0a9992e77c.png)
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]

Androd Gradle 对其使用模块依赖的替换

异步、邮件、定时三大任务

Matlab Doppler effect produces vibration signal and processing

Strongly connected components of digraph
随机推荐
合并K个已排序的链表
看疫情之下服装企业如何顺势而为
leetcode 2097 — 合法重新排列数对
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
无向图的割点
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
Merge K sorted linked lists
Kivy tutorial - example of using Matplotlib in Kivy app
Excel removes the data after the decimal point and rounds the number
Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
MongoDB系列之MongoDB常用命令
[C language] branch and loop statements (Part 1)
On Fibonacci sequence
拥抱平台化交付的安全理念
tp6快速安装使用MongoDB实现增删改查
12_微信小程序之微信视频号滚动自动播放视频效果实现
Basic concept and implementation of overcoming hash
The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
安全运营四要素之资产、脆弱性、威胁和事件