查询
Select count(*) from tb_door;#查询tb_door表中的总记录数
SELECT * FROM tb_door;#查询tb_door表中的所有记录(插入的内容/数据)
修改
1.修改tb_door表中id为1的记录
update tb_door set tel=555 where id=1;
2.修改字段类型:alter table 表名 modify 字段名称 字段类型();
增加(插入记录、添加加字段)
insert into tb_door values(null,'永和大王1店',666);
insert into tb_door values(null,' 永和大王2店',888);
2.增加字段:alter table 表名 add column 字段名称 类型();
删除
删除tb_door表中id为2的数据
Delete from tb_door where id=2;
查询语句
where
SELECT empno,ename,job FROM emp;#从表中查询指定字段
SELECT *FROM emp WHERE empno=100
SELECT *FROM emp WHERE sal>=8000
基础函数
SELECT empno,ename,job FROM emp;#查编号和名字
SELECT empno a,ename b FROM emp; #1.设置别名
SELECT ename, UPPER(ename) a FROM emp; #2.数据转大写
SELECT 'ABC',LOWER('ABC') FROM emp;
#lower转小写
SELECT ename,LOWER(ename) FROM emp;
#lengtn求长度 ,根据u8,一个字母或数字长度为1,一个汉子长度为3
SELECT ename, LENGTH(ename) FROM emp; #字段长度
SELECT ename,job, LENGTH(job) FROM emp;
#substr截取子串
#substr(a,b)--a是截取谁,b是从哪个字符开始,c是截取的长度
SELECT ename,SUBSTR(ename,2) FROM emp;
SELECT ename,SUBSTR(ename,2,2)FROM emp; #3
SELECT ename,CONCAT(ename,123,'asd',6) FROM emp;#4.concat拼接
SELECT ename,REPLACE(ename,'a','666')FROM emp; #5.replace替换,把ename中的a替换成666
SELECT comm, IFNULL(comm,10) FROM emp;#6.判断,如果comm是null,用10替换
#round ceil floor uuid() distinct
SELECT comm ,ROUND(comm)FROM emp;#四舍五入取整
SELECT comm ,ROUND(comm,1)FROM emp;#四舍五入保留一位小数
SELECT comm,CEIL(comm)FROM emp;#向上取整
SELECT comm,FLOOR(comm) FROM emp;#向下取整
SELECT UUID();#生成一个32为的随机字串
SELECT NOW();
##写错select now(year()),now(month()),now(day());
SELECT YEAR(NOW()),MONTH(NOW()),DAY(NOW());#获取当前的年月日
SELECT HOUR(NOW()),MINUTE(NOW()),SECOND(NOW());#获取当前的时分秒
SELECT 'xi\'an';
SELECT "xi'an";
##写错select loc,distinct(loc)from dept;
##select loc distinct from dept
SELECT DISTINCT loc FROM dept;#除去字段loc中重复的数据
SELECT DISTINCT depno FROM emp;
SELECT *FROM dept WHERE dept=1;
SELECT *FROM dept WHERE dept!=1;
SELECT *FROM dept WHERE dept<>1;
SELECT dname FROM dept WHERE dept>1;
SELECT dept FROM dept WHERE dname='research';#查询名称是research的部门编号
SELECT dname FROM dept WHERE loc='二区' AND dept=3;#查询地址在二区编号为3的部门名称
###select dname from dept in dept(1,2,3);
SELECT dname FROM dept WHERE dept IN(1,2,3)#查询dept中含123的编号 in只能查询统一字段中的条件
模糊查询
like
SELECT *FROM emp WHERE ename LIKE '%a%';
SELECT *FROM emp WHERE ename LIKE 'l__';
SELECT *FROM emp WHERE ename LIKE 'a%';
SELECT *FROM emp WHERE ename LIKE '%a';