当前位置:网站首页>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;
边栏推荐
- Verilog实现占空比为5/18的9分频
- Anaconda如何顺利安装CV2
- Taobao/Tmall get Taobao password real url API
- iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
- 阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
- MySQL---多表查询
- 如何识别假爬虫?
- 每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
- server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none 失败
- 牛客网刷题(二)
猜你喜欢
Flex布局详解
这位985教授火了!当了10年博导,竟无一博士毕业!
Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
After Effects 教程,如何在 After Effects 中调整过度曝光的快照?
flowable工作流所有业务概念
[pytorch] 1.7 pytorch and numpy, tensor and array conversion
How C programs run 01 - the composition of ordinary executable files
【码蹄集新手村600题】不通过字符数组来合并俩个数字
仿生毛毛虫机器人源码
AcWing 1282. 搜索关键词 题解((AC自动机)Trie+KMP)+bfs)
随机推荐
Flex布局详解
Flutter set the background color of the statusbar status bar and APP method (AppBar) internal consistent color.
Flutter 获取状态栏statusbar的高度
Golang 小数操作之判断几位小数点与四舍五入
Go record - slice
【luogu P8326】Fliper (Graph Theory) (Construction) (Eulerian Circuit)
MySQL---运算符
组合学笔记(六)局部有限偏序集的关联代数,Möbius反演公式
js的toString方法
牛客 HJ20 密码验证合格程序
Masterless replication system (2) - read and write quorum
Design and Implementation of Compiler Based on C Language
Small program: Matlab solves differential equations "recommended collection"
使用互相关进行音频对齐
Multi-datacenter operation and detection of concurrent writes
Golang 切片删除指定元素的几种方法
UserAgent 解析
保证接口数据安全的10种方式
自动化测试—web自动化—selenium初识
How C programs run 01 - the composition of ordinary executable files