当前位置:网站首页>MySQL---Basic select statement
MySQL---Basic select statement
2022-07-31 17:20:00 【Narwhals need water】
基本的select语句
基本的语句
语法
select 标识选择哪些列
from Identify from which select in the table
选择全部列(不推荐)
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语句中使用一对``(着重号)引起来
Add a list of query results in fixed often series
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;
边栏推荐
- LevelSequence源码分析
- 组合学笔记(六)局部有限偏序集的关联代数,Möbius反演公式
- mysql的备份表的几种方法
- AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
- Concurrency, Timing and Relativity
- 牛客 HJ19 简单错误记录
- Handling write conflicts under multi-master replication (3) - Convergence to a consistent state and custom conflict resolution logic
- 仿生毛毛虫机器人源码
- ECCV 2022 华科&ETH提出首个用于伪装实例分割的一阶段Transformer的框架OSFormer!代码已开源!...
- A common method and the use of selenium
猜你喜欢
Smart Trash Can (8) - Infrared Tube Sensor (Raspberry Pi pico)
这位985教授火了!当了10年博导,竟无一博士毕业!
This 985 professor is on fire!After 10 years of Ph.D. supervisor, no one has graduated with a Ph.D.!
Go basic part study notes
Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
Kotlin协程:续体、续体拦截器、调度器
21.支持向量机—核函数的介绍
[Network Communication 3] Advantech Gateway Modbus Service Settings
Flink_CDC搭建及简单使用
【pytorch】pytorch 自动求导、 Tensor 与 Autograd
随机推荐
无主复制系统(2)-读写quorum
LevelSequence源码分析
Kotlin coroutines: continuation, continuation interceptor, scheduler
几款永久免费内网穿透,好用且简单(内网穿透教程)
华为顶级工程师历时9年总结的“趣谈网络协议”PDF文档,太强了
Mariabackup implements incremental data backup for Mariadb 10.3
Intelligent bin (9) - vibration sensor (raspberries pie pico implementation)
cas与自旋锁(轻量级锁就是自旋锁吗)
阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
Huawei mobile phone one-click to open "maintenance mode" to hide all data and make mobile phone privacy more secure
BOW/DOM(上)
【码蹄集新手村600题】通向公式与程序相结合
MySQL---Subqueries
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
[TypeScript]OOP
多主复制下处理写冲突(1)-同步与异步冲突检测及避免冲突
flyway的快速入门教程
GateWay实现负载均衡
flutter设置statusbar状态栏的背景颜色和 APP(AppBar)内部颜色一致方法。
保证接口数据安全的10种方式