当前位置:网站首页>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;
边栏推荐
- 杰理语音芯片ic玩具芯片ic的介绍_AD14NAD15N全系列开发
- tensorflow2.0 cnn(layerwise)
- Design and Implementation of Compiler Based on C Language
- 入职一个月反思
- MySQL常用语句整理
- Flex布局详解
- IP protocol from 0 to 1
- EF Core 2.2中将ORM框架生成的SQL语句输出到控制台
- adb shell 报错error: device unauthorized
- 每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
猜你喜欢
Golang 小数操作之判断几位小数点与四舍五入
The new telecom "routine", my dad was tricked!
2022年整理LeetCode最新刷题攻略分享(附中文详细题解)
How Redis handles concurrent access
Huawei mobile phone one-click to open "maintenance mode" to hide all data and make mobile phone privacy more secure
TestCafe总结
华为手机一键开启“维修模式”隐藏所有数据,让手机隐私更加安全
Kotlin coroutines: continuation, continuation interceptor, scheduler
基于WPF重复造轮子,写一款数据库文档管理工具(一)
智能垃圾桶(九)——震动传感器(树莓派pico实现)
随机推荐
Verilog实现占空比为5/18的9分频
How Redis handles concurrent access
Go basic part study notes
【Yugong Series】July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
SringMVC中个常见的几个问题
浅谈网络安全之算法安全
牛客 HJ16 购物单
adb shell 报错error: device unauthorized
MySQL common statements
Premiere Pro 2022 for (pr 2022)v22.5.0
SHELL内外置命令
Handling write conflicts under multi-master replication (3) - Convergence to a consistent state and custom conflict resolution logic
Flink_CDC搭建及简单使用
go记录之——slice
IP protocol from 0 to 1
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
杰理语音芯片ic玩具芯片ic的介绍_AD14NAD15N全系列开发
Masterless Replication System (3)-Limitations of Quorum Consistency
复杂高维医学数据挖掘与疾病风险分类研究
【luogu P8326】Fliper(图论)(构造)(欧拉回路)