当前位置:网站首页>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;
边栏推荐
- Handling Write Conflicts under Multi-Master Replication (1)-Synchronous and Asynchronous Conflict Detection and Conflict Avoidance
- go记录之——slice
- TypeError: unhashable type: ‘list‘
- Flutter gets the height of the status bar statusbar
- Verilog实现占空比为5/18的9分频
- Design and Implementation of Compiler Based on C Language
- 基于WPF重复造轮子,写一款数据库文档管理工具(一)
- 【网络通信三】研华网关Modbus服务设置
- SringMVC中个常见的几个问题
- 你辛辛苦苦写的文章可能不是你的原创
猜你喜欢
随机推荐
2022 Android interview summary (with interview questions | source code | interview materials)
i.MX6ULL driver development | 33 - NXP original network device driver reading (LAN8720 PHY)
flowable工作流所有业务概念
二分查找的细节坑
多数据中心操作和检测并发写入
IP协议从0到1
TestCafe总结
LevelSequence源码分析
go记录之——slice
利用PHP开发具有注册、登陆、文件上传、发布动态功能的网站
Huawei's top engineers lasted nine years "anecdotal stories network protocol" PDF document summary, is too strong
你辛辛苦苦写的文章可能不是你的原创
牛客网刷题(一)
每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
Kotlin coroutines: continuation, continuation interceptor, scheduler
useragent在线查找
[TypeScript]OOP
如何识别假爬虫?
Mariabackup implements incremental data backup for Mariadb 10.3









