摘要:1、内连接 语法: SELECT 查询字段1,查询字段2, ... FROM 表1 [INNER] JOIN 表2 ON 表1.关系字段=表2.关系字段 准备数据 -- 若存在数据库mydb则删除 DROP DATABASE IF EXISTS mydb; -- 创建数据库mydb CREATE D
阅读全文
摘要:as关键字 1、为表取别名 SELECT * FROM 表名 [AS] 表的别名 WHERE .... ; select * from student as stu; 2、为字段取别名 SELECT 字段名1 [AS] 别名1 , 字段名2 [AS] 别名2 , ... FROM 表名 WHERE
阅读全文
摘要:1、count select count(*) from student; 2、max select max(age) from student; 3、min select sname,min(age) from student; 4、sum select sum(age) from student
阅读全文
摘要:为防止错误的数据插入到数据表,mysql中定义了一些维护数据库完整性的规则,这些规则就是表的约束
阅读全文
摘要:1、delete基本语法 DELETE FROM 表名 [WHERE 条件表达式]; 2、删除部分记录 delete from student where age=14; 3、删除全部数据 delete from student; 5、truncate和delete的区别 TRUNCATE和DETE
阅读全文
摘要:1、update基本语法 UPDATE 表名 SET 字段名1=值1[,字段名2 =值2,…] [WHERE 条件表达式]; 2、更新部分数据 update student set age=20,gender='female' where name='tom'; 3、更新全部数据 update st
阅读全文
摘要:1、向表中所有字段插入数据 INSERT INTO 表名(字段名1,字段名2,...) VALUES (值 1,值 2,...); 2、为表中指定字段插入数据 INSERT INTO 表名(字段名1,字段名2,...) VALUES (值 1,值 2,...); 3、向表中同时插入多条记录 INSE
阅读全文
摘要:1、创建数据表 create table student( id int, name varchar(20), gender varchar(10), birthday date ); 2、查看当前数据库中所有数据表 show tables; 3、查看某表所有字段信息 desc student; 4
阅读全文
摘要:1、创建数据库 create database 数据库名称; 2、删除数据库 drop database db1; 3、查询出mysql中所有的数据库 show databases; 4、切换使用数据库 use db1; 5、查看当前使用的数据库 select database(); 6、将数据库的
阅读全文
摘要:SQL语句的执行顺序: 1、from:确定表的连接关系 2、where:对数据进行初步的筛选 3、group by:数据分组 4、having:对分组后数据进行筛选 5、select:结果输出 6、结果去重:distinct 7、排序:order by
阅读全文
摘要:LIKE操作符:通配符搜索只能用于文本字段(字符串) 1、%通配符 1 select 2 col_name 3 from 4 table_name 5 where 6 col_name 7 like "%str" 2、_通配符 1 select 2 col_name 3 from 4 table_n
阅读全文
摘要:1、组合WHERE子句 1.1、AND操作符 1 select 2 col_name 3 from 4 table_name 5 where 6 col_name = 'str' 7 and 8 col_name2 = 'str'; 1.2、OR操作符 1 select 2 col_name 3 f
阅读全文
摘要:主要是WHERE关键字的使用,对分组前的数据进行过滤 1、where子句操作符 以上有些操作是冗余的,注意并非DBMS都支持不同的写法,具体要看 2、检查单个值 1 select 2 col_name 3 from 4 table_name 5 where 6 col_name < num; 3、不
阅读全文
摘要:ORDER BY子句必须是SELECT语句中最后一条子句 1、排序数据 1 select 2 col_name 3 from 4 table_name 5 order by 6 col_name; 2、按多个列排序 1 select 2 col_name, 3 col_name2 4 from 5
阅读全文
摘要:1、检索单个列 1 select 2 col_name 3 from 4 table_name; 2、检索多个列 1 select 2 col_name, 3 col_name2 4 from 5 table_name; 3、检索所有列 使用·*通配符可以实现,但是一般而言,除非确实需要表中的每一列
阅读全文
摘要:结构化查询语言,是一门操作关系型数据库的语言 和mysql完全是两码事 DDL:数据库定义语言 DML:数据库操作语言 DCL:数据库控制语言 DQL:数据库查询语言 1、背景 前不久 ,买了本SQL必知必会,看了下,然后就开始在某客网刷题,从此篇起, 1、准备结合<<SQL必知必会>>和某客网的题
阅读全文