栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 数据挖掘与分析

数据库day02笔记

数据库day02笔记

set names gbk  解决中文乱码


CREATE TABLE c1(
id INT PRIMARY KEY AUTO_INCREMENT,
pwd VARCHAr(10) NOT NULL
)
主键自增策略(auto_increment)
not null  非空约束
unique--唯一约束
SELECt dname FROM dept   查询


lower 全转小写
SELECt 'ABC',LOWER('ABC') from dept; --数据转小写

upper 全转大写
select upper(dname) from dept --数据转大写

length 长度
select length(dname) from dept --数据的长度

substr 截取
substr(a,b,c) a是字段名, b是截取的开始位置, c是截取的长度

concat 拼接
concat(a,b,c) a是字段名, b是想要拼接的内容, c也是想要拼接的内容

replace 替换

select dname,replace(dname,'a','666') X from dept --把a字符替换成666

ifnull 判断
select ifnull(comm,10) comm from dept2 #判断,如果comm是null,用10替换

round & ceil & floor  对小数的处理
round四舍五入,ceil向上取整,floor向下取整
select comm,round(comm),ceil(comm),floor(comm)from emp

now year month day   对日期的处理
select now(),year(now()),month(now()),day(now())获取 年 月 日
select now(),hour(now()),minute(now()),second(now()) 获取时 分 秒


distinct  去重
select distinct loc from dept

where 哪里  查询
select * from dept where deptno=666 唯一条件
select * from dept where deptno>333 and loc='二区'  多个条件 用and并且 / or或者 连接
简化查询
SELECt * FROM dept WHERe deptno IN(333,666,999)
FROM dept WHERe deptno NOT IN(333,999)  

like 模糊查询   %是通配符
'l%' --以l开头的
'%a' --以a结束的
'%a%' --中间包含a的
'l__' --l后面有两个字符的 _代表一个字符位置
select * from emp where ename like 'l%'
select * from emp where ename like '%o%'

null 数据处理
select * from emp where comm is null
select * from emp where comm  is not null

between...and   在区间范围内的数据 
select * from emp where sal between 3000 and 10000

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/279019.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号