当前位置:网站首页>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
边栏推荐
猜你喜欢

Excel visualization

HCM Beginner (IV) - time

C language course set up salary management system (big homework)

Forkjoin and stream flow test

MongoDB:一、MongoDB是什么?MongoDB的优缺点

SystemVerilog learning-08-random constraints and thread control

idea 好用插件汇总!!!

【ITSM】什么是ITSM,IT部门为什么需要ITSM

C language course set up property fee management system (big work)

异常检测方法梳理,看这篇就够了!
随机推荐
Minio error correction code, construction and startup of distributed Minio cluster
IT服务管理(ITSM)在高等教育领域的应用
Comment imprimer le tableau original
【企业数据安全】升级备份策略 保障企业数据安全
SystemVerilog learning-08-random constraints and thread control
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
请求模块(requests)
【ITSM】什么是ITSM,IT部门为什么需要ITSM
Three minutes to quickly understand the whole process of website development
HDU - 1501 zipper (memory deep search)
Treasure taking from underground palace (memory based deep search)
Code power is full of quantitative learning | how to find a suitable financial announcement in the financial report
Student attendance system for C language course (big homework)
【Unity Shader 描边效果_案例分享第一篇】
On siem
Promise
C语言课设图书信息管理系统(大作业)
[ManageEngine Zhuohao] mobile terminal management solution, helping the digital transformation of Zhongzhou aviation industry
【ManageEngine】如何实现网络自动化运维
B-tree series