测试必会的Mysql语句

创建数据库:create database 库名
删除数据库:drop database  库名
显示数据库:show databases;
创建表:create table 1708A(id int primary key auto_increment,name varchar(50),age int,address varchar(50));

查询语句
查询所有: select * from 表名;
查特定列: select name,age from 表名;
多条件 并关系 查询: select * from 1708A where name="郝甜甜" and id="2";
多条件 或关系查询:  select * from 1708A where name="白嘉诚" or id = "2";
范围查询:select * from 1708A where id<3 and name="白嘉诚";
范围查询: select * from 1708A where id between 1 and 2;
模糊查询:select * from 1708A where name like "%嘉%";
序列查询-升序排列: select * from 1708A order by age asc;
序列查询-降序排列: select * from 1708A order by age desc;
统计函数-查询表中有多少条id数据: select count(id) from 1708A;
统计函数-查询表中有多少条符合条件数据: select count(name) from 1708A where name like '白%';
获取字段最大值: select max(age) from 1708A;
获取字段最小值: select min(age) from 1708A;
获取字段平均值: select avg(age) from 1708A;
获取字段总和: select sum(age) from 1708A;
分页查询-跳过几条数据取几条数据:select * from limit 0,2;   limit->限制
内连接: select * from 1708A inner join 1709A on 1708A.id = 1709A.id;
左连接: select * from 1708A left join 1709A on 1708A.id = 1709A.id; 
右连接: select * from 1708A right join 1709A on 1708A.id = 1709A.id;



插入数据
字段对值插入:insert into 1708A(name,age,address) values("白嘉诚",22,"吉林省吉林市");

插入列
插入一列: alter table 1708A add class int;

更多查询语句:

https://www.cnblogs.com/yiyide266/p/7594058.html

原创文章 34 获赞 216 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_46457203/article/details/105850307