当前位置:网站首页>MySQL---基本的select语句
MySQL---基本的select语句
2022-07-31 17:00:00 【独角鲸需要水】
基本的select语句
基本的语句
语法
select 标识选择哪些列
from 标识从哪些表中选择
选择全部列(不推荐)
select *
from departments;
选择特定的列
select department_id,location_id
from departments;
列的别名
select last_name as name,commission_pct comm
from employees;
select last_name "name",salary*12 "annual Salary"
from employees;
去除重复行
select distinct department_id
from employees;
空值参与运算
所有运算符或列值遇到null值,运算的结果都为null
在 MySQL 里面, 空值不等于空字符串。一个空字符串的长度是 0,而一个空值的长
度是空。而且,在 MySQL 里面,空值是占用空间的
SELECT employee_id,salary,commission_pct,
12 * salary * (1 + commission_pct) "annual_sal"
FROM employees;
着重号
SELECT * FROM `ORDER`;
我们需要保证表中的字段、表名等没有和保留字、数据库系统或常用方法冲突。如果真的相同,请在
SQL语句中使用一对``(着重号)引起来
查询结果中增加一列固定常数列
select 'MySQL' corporation ,last_name
from employees
查询表结构
DESC employees;
或
describe employees;
过滤where
select 字段1,字段2
from 表名
where 过滤条件
select employee_id, last_name, job_id, department_id
from employees
where department_id = 90 ;
练习
1.查询员工12个月的工资总和,并起别名为ANNUAL SALARY
select employee_id,last_name,salary*12 "ANNUAL SALARY"
from employees;
select employee_id,last_name,salary*12 *(1+ifnull(commission_pct,0)) "ANNUAL SALARY"
from employees;
2.查询employees表中去除重复的job_id以后的数据
select distinct job_id
from employees;
3.查询工资大于12000的员工姓名和工资
SELECT last_name,salary
FROM employees
WHERE salary > 12000;
4.查询员工号为176的员工的姓名和部门号
SELECT last_name,department_id
FROM employees
WHERE employee_id = 176;
5.显示表 departments 的结构,并查询其中的全部数据
DESC departments;
SELECT * FROM departments;
边栏推荐
- Flutter set the background color of the statusbar status bar and APP method (AppBar) internal consistent color.
- go记录之——slice
- ECCV 2022 华科&ETH提出首个用于伪装实例分割的一阶段Transformer的框架OSFormer!代码已开源!...
- 2022年必读的12本机器学习书籍推荐
- mysql的备份表的几种方法
- AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
- JS基础小练习
- 研发过程中的文档管理与工具
- tensorflow2.0 cnn(layerwise)
- Huawei's top engineers lasted nine years "anecdotal stories network protocol" PDF document summary, is too strong
猜你喜欢
[TypeScript] OOP
【网络通信三】研华网关Modbus服务设置
上传图片-微信小程序(那些年的坑记录2022.4)
【C语言】LeetCode27.移除元素
宁波大学NBU IT项目管理期末考试知识点整理
IP协议从0到1
How C programs run 01 - the composition of ordinary executable files
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
After Effects tutorial, How to adjust overexposed snapshots in After Effects?
AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
随机推荐
迁移学习——Domain Adaptation
宁波大学NBU IT项目管理期末考试知识点整理
如何识别假爬虫?
每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
【NLP】什么是模型的记忆力!
智能垃圾桶(八)——红外对管传感器(树莓派pico)
【源码解析】BeanFactory和FactoryBean
Mariabackup实现Mariadb 10.3的增量数据备份
Golang 切片删除指定元素的几种方法
Design and Implementation of Compiler Based on C Language
go图书管理系统
tensorflow2.0 cnn(layerwise)
多主复制下处理写冲突(1)-同步与异步冲突检测及避免冲突
The new telecom "routine", my dad was tricked!
SringMVC中个常见的几个问题
After Effects tutorial, How to adjust overexposed snapshots in After Effects?
Masterless Replication System (3)-Limitations of Quorum Consistency
Istio介绍
无主复制系统(2)-读写quorum
How to install CV2 smoothly in Anaconda