当前位置:网站首页>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
边栏推荐
- [unity shader amplify shader editor (ASE) Chapter 9]
- [unity shader custom material panel part I]
- [leetcode] day91- duplicate elements exist
- 三分钟带你快速了解网站开发的整个流程
- Self confidence is indispensable for technology
- 地宫取宝(记忆化深搜)
- Movable mechanical wall clock
- Tidb database characteristics summary
- Three minutes to quickly understand the whole process of website development
- How does the port scanning tool help enterprises?
猜你喜欢

ForkJoin和Stream流测试

Design of sales management system for C language course (big homework)

浅谈SIEM
![[summary of knowledge points] chi square distribution, t distribution, F distribution](/img/a6/bb5cabbfffb0edc9449c4c251354ae.png)
[summary of knowledge points] chi square distribution, t distribution, F distribution

HCM Beginner (I) - Introduction

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

连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
![[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map](/img/c0/299a406efea51f24b1701b66adc1e3.png)
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map

手把手教你实现一个深度学习框架...

Redis安装到Windows系统上的详细步骤
随机推荐
【#Unity Shader#自定义材质面板_第二篇】
地宫取宝(记忆化深搜)
【Unity Shader 描边效果_案例分享第一篇】
Three minutes to quickly understand the whole process of website development
Code power is full of quantitative learning | how to find a suitable financial announcement in the financial report
[unity shader ablation effect _ case sharing]
扩散(多源广搜)
[ITSM] what is ITSM and why does it department need ITSM
【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
Application of IT service management (ITSM) in Higher Education
lxml模块(数据提取)
libpng12.so. 0: cannot open shared object file: no such file or directory
C language course set up library information management system (big homework)
Mysql 表分区创建方法
Pychart configuring jupyter
JDBC connection pool
C语言课设学生考勤系统(大作业)
JMM详解
记磁盘扇区损坏导致的Mysql故障排查
C language course set up student elective course system (big homework)