当前位置:网站首页>SQL语言的学习记录一
SQL语言的学习记录一
2022-07-01 06:21:00 【小美元】
sql语言语言的分类
DDL(数据定义语言):CREATE\ALTER\DROP\RENAME\TURNCATE
DML(数据操作语言);INSERT\DELETE\UPDATE\SELECT
DCL(控制语言):COMMIT\ROLLBACK\SAVEPOINT\GRANT\REVOKE
sql语言的规则和规范:
规则:
1\注释的三种方式
/* */多行注释
– 注释
"#"也是一种注释
2、导入现有的数据表
1.source 文件路径
2.图形化界面
show databases 显示数据库
source 路径
use atguigudb;
show tables
列的别名的三种方式
SELECT employ_id emp_id FROM employee
加sa
加双引号
DISTINCT
select distinct department_id from employee
去除重复的数据
空值运算
空值参与运算结果也为null 因此空值不算是“null” 也不算是0
SELECT employee_id,salary,salary * IFNULL(( 1 + commission_pct),0) * 12 as 年工资 FROM employees;
着重号
如果表明和关键字重名需要加“ `` ”来进行使其恢复正常运行
DESCRIVE
显示表结构 describe employees;
DESC employees;
过滤条件
查询90号部门的员工信息
select * from employeee where name = ‘king’
单引号mysql区分大小写,ocrale区分大小写
+ - * / div % mod
- SELECT 100 + ‘1’ FROM DUAL; 查出来是101
java中结果是1001,sql中就表示加法运算(隐式转换)- SELECT 100 + ‘a’ FROM DUAL; 此时将a看做0来处理
比较运算符
<=> 安全等于
<>不等于
字符串‘a’被看成0的值
如果纯粹字符串和字符串比较就不会是隐式转换数值了
只要有null参与结果就为null,如果要查询数值中为null的数据应该使用安全等于
IS NULL \IS NOT NULL \ ISNULL
WHERE ISNULL(commission_pct);
where comminssion_pct <=> null
where not commission_pct <=> null;
least \greatest
in
SELECT department_id ,last_name from employees WHERE department_id in (10,20,30);
查询部门号是10,20,30的人的信息
like
SELECT last_name FROM employees where last_name like ‘%a%’;
百分号代表不确定个数的字符(0个1个多个)
SELECT last_name FROM employees where last_name like ‘a%’;
以a开头的字符
包含字符a且包含字符e的
SELECT last_name FROM employees where last_name like ‘%a%e%’ or last_name like “%e%a%”;
包含e且包含a的数据
- _第二个字符为a
SELECT last_name FROM employees where last_name like ‘__a%’;
逻辑运算符
或 || and
与 && or
and 的优先级高于 or的优先级
优先级可以不用记加个小括号就完美
排序操作
如果没有排序是默认按照添加的顺序实现的
使用orderby对查询到的顺序进行排序操作
升序:asc 默认按照升序排列由低到高
降序:desc
SELECT employee_id,salary from employees ORDER BY salary desc;
列的别名只能在orderby中使用不能在where中使用
分页
SELECT * FROM employees
LIMIT 0,20
分页显示从0开始第20条数据
显示第二页的数据
limit 20,20
边栏推荐
- 阶乘约数(唯一分解定理)
- Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
- Elements of database ER diagram
- C语言课设物业费管理系统(大作业)
- C语言课设学生选修课程系统(大作业)
- SQL语句
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
- [unity shader stroke effect _ case sharing first]
- SystemVerilog learning-06-class encapsulation
- Make: g++: command not found
猜你喜欢

C language course set up library information management system (big homework)

B-树系列

Application of IT service management (ITSM) in Higher Education

C语言课设物业费管理系统(大作业)

自开发软件NoiseCreater1.1版本免费试用

Promise

浅谈SIEM

C语言课设工资管理系统(大作业)

【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】

SystemVerilog learning-10-validation quantification and coverage
随机推荐
sql中TCL语句(事务控制语句)
What are the functions of LAN monitoring software
[unity shader stroke effect _ case sharing first]
[ManageEngine] terminal management system helps Huasheng securities' digital transformation
虚幻 简单的屏幕雨滴后处理效果
【Unity Shader 消融效果_案例分享】
C language course design student information management system (big homework)
C语言课设学生选修课程系统(大作业)
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
UOW of dev XPO comparison
做技术,自信不可或缺
[enterprise data security] upgrade backup strategy to ensure enterprise data security
[unity shader custom material panel part I]
B-tree series
Make: g++: command not found
网络爬虫
启牛学堂合作的证券公司是哪家?开户安全吗?
C语言课设销售管理系统设计(大作业)
Projects and dependencies in ABP learning solutions
C语言课设工资管理系统(大作业)