当前位置:网站首页>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;

边栏推荐
- [day 29] given an integer, please find its factor number
- Strongly connected components of digraph
- Do not log in or log in to solve the problem that the Oracle database account is locked.
- Basic concept and implementation of overcoming hash
- 【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
- JS inheritance and prototype chain
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- Every k nodes in the linked list are flipped
- 按键精灵打怪学习-自动回城路线的判断
- 基本远程连接工具Xshell
猜你喜欢

Excel calculates the difference between time and date and converts it into minutes

(C language) data storage

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

无向图的割点

MySQL foundation 04 MySQL architecture

【FPGA教程案例6】基于vivado核的双口RAM设计与实现

12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet

【无标题】

leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】

用Go+绘制爱心给心爱的她表白
随机推荐
The industrial scope of industrial Internet is large enough. The era of consumer Internet is only a limited existence in the Internet industry
Basic remote connection tool xshell
Look at how clothing enterprises take advantage of the epidemic
[self management] time, energy and habit management
鏈錶內指定區間反轉
1038 Recover the Smallest Number
Inversion de l'intervalle spécifié dans la liste des liens
Linear programming of mathematical modeling (including Matlab code)
matlab 多普勒效应产生振动信号和处理
Several cases of recursive processing organization
ROS2之ESP32简单速度消息测试(极限频率)
LDC Build Shared Library
寻找标杆战友 | 百万级实时数据平台,终身免费使用
excel表格计算时间日期的差值,并转化为分钟数
Delete duplicate elements in the ordered linked list -ii
Database SQL language 01 where condition
Makefile中wildcard、patsubst、notdir的含义
excel IF公式判断两列是否相同
MongoDB系列之MongoDB常用命令
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life