当前位置:网站首页>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;
边栏推荐
- Database SQL language 02 connection query
- leetcode 2097 — 合法重新排列数对
- 基本远程连接工具Xshell
- Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
- MySQL foundation 04 MySQL architecture
- 安全运营四要素之资产、脆弱性、威胁和事件
- 异步、邮件、定时三大任务
- 机器学习术语
- Key wizard play strange learning - front desk and Intranet send background verification code
- Matlab Doppler effect produces vibration signal and processing
猜你喜欢
[AUTOSAR 11 communication related mechanism]
matlab 多普勒效应产生振动信号和处理
Excel calculates the difference between time and date and converts it into minutes
Asynchronous, email and scheduled tasks
拥抱平台化交付的安全理念
Assets, vulnerabilities, threats and events of the four elements of safe operation
[AUTOSAR XIII NVM]
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
有向图的强连通分量
【FH-GFSK】FH-GFSK信号分析与盲解调研究
随机推荐
Asynchronous, email and scheduled tasks
Linear programming of mathematical modeling (including Matlab code)
leetcode:701. Insertion in binary search tree [BST insertion]
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
【FH-GFSK】FH-GFSK信号分析与盲解调研究
Basic concept and implementation of overcoming hash
数据分析思维分析犯法和业务知识——分析方法(一)
(C语言)数据的存储
这不平凡的两年,感谢我们一直在一起!
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
正确甄别API、REST API、RESTful API和Web Service之间的异同
[自我管理]时间、精力与习惯管理
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
(C language) data storage
比较版本号
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
Merge K sorted linked lists
MySQL foundation 04 MySQL architecture
Understanding and distinguishing of some noun concepts in adjustment / filtering
1038 Recover the Smallest Number