当前位置:网站首页>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;
边栏推荐
猜你喜欢
![[TypeScript] OOP](/img/d7/b3175ab538906ac1b658a9f361ba44.png)
[TypeScript] OOP
How Redis handles concurrent access

IP协议从0到1

GP 6 overall architecture study notes

【pytorch】pytorch 自动求导、 Tensor 与 Autograd

Implementing distributed locks based on Redis (SETNX), case: Solving oversold orders under high concurrency

go mode tidy出现报错go warning “all“ matched no packages

After Effects tutorial, How to adjust overexposed snapshots in After Effects?

利用PHP开发具有注册、登陆、文件上传、发布动态功能的网站

如何识别假爬虫?
随机推荐
【码蹄集新手村600题】通向公式与程序相结合
牛客 HJ16 购物单
研发过程中的文档管理与工具
多主复制下处理写冲突(3)-收敛至一致的状态及自定义冲突解决逻辑
深度学习机器学习理论及应用实战-必备知识点整理分享
Automated testing - web automation - first acquaintance with selenium
How Redis handles concurrent access
迁移学习——Domain Adaptation
Mariabackup implements incremental data backup for Mariadb 10.3
动态规划(一)
牛客网刷题(二)
SringMVC中个常见的几个问题
基于WPF重复造轮子,写一款数据库文档管理工具(一)
Last write wins (discards concurrent writes)
【luogu P8326】Fliper (Graph Theory) (Construction) (Eulerian Circuit)
Golang 切片删除指定元素的几种方法
LevelSequence源码分析
How C programs run 01 - the composition of ordinary executable files
go记录之——slice
2022年Android 面经总结(附含面试题 | 源码 | 面试资料)