当前位置:网站首页>MySQL --- 数据库查询 - 基本查询
MySQL --- 数据库查询 - 基本查询
2022-07-03 00:55:00 【小雪菜本菜】
基本查询
MySQL 数据库使用SELECT语句来查询数据。
1. 查询多个字段
以下为在MySQL数据库中查询数据通用的 SELECT 语法:
SELECT 字段名,字段名... FROM 表名;
SELECT * FROM 表名; #查询所有字段查询语句中可以使用一个或者多个表,表之间使用逗号(,)分割,并使用WHERE语句来设定查询条件。
SELECT 命令可以读取一条或者多条记录。
你可以使用星号(*)来代替其他字段,SELECT语句会返回表的所有字段数据
2.设置别名
SELECT 字段1 [AS 别名],字段2 [AS 别名]... FROM 表名;3.去除重复记录
SELECT DISTINCT 字段列表 FROM 表名;4.四则运算查询

查询需求


查看文件编码
怎么往 Navicat 里面导入 sql 数据呢?

开始查询操作

1.查询指定字段 ename,job,sal的数据
SELECT ename,job,sal FROM emp;
2.查询所有字段
SELECT empno,ename,job,mgr,hiredate,comm,deptno FROM emp;
或者采用下面这种方法查询所有字段
①不够直观,不能一眼就看出有哪些字段
②影响执行效率,首先要去表里面找有哪些字段,然后再去查,多了一个找的步骤
-- 不推荐直接使用 * --
SELECT * FROM emp;
3.查询所有员工的职位,并起别名
SELECT ename,job FROM emp;
起别名
SELECT ename,job AS '工作岗位' FROM emp;
AS 可以省略
SELECT ename,job '工作岗位' FROM emp;
4.查询员工的的职位有哪些(不要重复)
SELECT job FROM emp;注意观察有重复的,需要把重复的只显示一个就可以了

使用 DISTINCT 关键字去重
SELECT DISTINCT job FROM emp;
如果有多个字段,不能去除掉重复的,这个是对于单个字段的去重

5.查询员工年薪 即 sal * 12
SELECT ename,sal AS '月薪',sal * 12 AS '年薪' FROM emp;
SELECT sal / 10 FROM emp;
SELECT sal DIV 10 FROM emp;

边栏推荐
- Key wizard play strange learning - multithreaded background coordinate recognition
- Excel calculates the difference between time and date and converts it into minutes
- 解决ReactNative使用webView存在缓存问题
- excel去除小数点后面的数据,将数字取整
- 【爱死机】《吉巴罗》被忽略的细节
- RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
- Initial order of pointer (basic)
- Canvas drawing -- bingdd
- Matlab Doppler effect produces vibration signal and processing
- 基本远程连接工具Xshell
猜你喜欢

Reading and writing speed of Reza rz/g2l arm development board storage and network measurement

Thank you for being together for these extraordinary two years!
![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]
![[Arduino experiment 17 L298N motor drive module]](/img/e2/4511eaa942e4a64c8ca2ee70162785.jpg)
[Arduino experiment 17 L298N motor drive module]

MySQL basics 03 introduction to MySQL types

基本远程连接工具Xshell

全志A40i/T3如何通过SPI转CAN

Linear programming of mathematical modeling (including Matlab code)

Explain the basic concepts and five attributes of RDD in detail

Cut point of undirected graph
随机推荐
解决ReactNative使用webView存在缓存问题
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
Solve the cache problem of reactnative using WebView
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
[AUTOSAR twelve mode management]
拥抱平台化交付的安全理念
Initial order of pointer (basic)
R language uses coin package to apply permutation tests to independence problems (permutation tests, whether response variables are independent of groups, are two numerical variables independent, and
leetcode 6103 — 从树中删除边的最小分数
[introduction to AUTOSAR seven tool chain]
有向图的强连通分量
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
MySQL foundation 05 DML language
matlab 多普勒效应产生振动信号和处理
[overview of AUTOSAR three RTE]
【无标题】
Key wizard play strange learning - front desk and Intranet send background verification code
Several cases of recursive processing organization
Excel removes the data after the decimal point and rounds the number
详解RDD基本概念、RDD五大属性