美文网首页
软件测试必备MySQL语句查询

软件测试必备MySQL语句查询

作者: luckyer | 来源:发表于2019-03-15 13:06 被阅读0次

1 | 查询所有数据 

select * from Info 查所有数据

select Code,Name from Info 查特定列

 2 | 根据条件查 

select * from Info where Code='p001' 一个条件查询

select * from Info where Code='p001' and Nation='n001' 多条件 并关系 查询

select * from Info where Name='胡军' or Nation='n001' 多条件 或关系 查询

select * from Car where Price>=50 and Price<=60 范围查询

select * from Car where Price between 50 and 60 范围查询

3 | 模糊查询 

select * from Car where Name like '%型' %通配符代表任意多个字符

select * from Car where Name like '%奥迪%' 

select * from Car where Name like '_马%'_通配符代表任意一个字符

 4| 排序 

select * from Car order by Price asc 按照价格升序排列

select * from Car order by Price desc 按照价格降序排列

select * from Car order by Price,Oil 按照两列进行排序,前面的为主要的

 5 | 统计函数(聚合函数)

select count(Code) from Car 查询表中有多少条数据

select max(Price) from Car 取价格的最大值

select min(Price) from Car 取价格的最小值

select sum(Price) from Car 取价格的总和

select avg(Price) from Car 取价格的平均值

 6 | 分组查询 

select Brand from Car group by Brand having count(*)>2 查询所有系列中数量大于2的

 7 | 分页查询 

select * from Car limit 0,5 跳过几条数据取几条数据

 8 | 去重查询 

select distinct Brand from Car

 9 | 表中增加一列

如果想在一个已经建好的表TABLE_NAME中添加一列,可以用诸如:

alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null;

这条语句会向已有的表中加入新的一列,这一列在表的最后一列位置。如果我们希望添加在指定的一列,可以用:

alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null after COLUMN_NAME;

注意,上面这个命令的意思是说添加新列到某一列后面。如果想添加到第一列的话,可以用:

alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null first;

相关文章

  • 软件测试必备MySQL语句查询

    1 | 查询所有数据 select * from Info 查所有数据 select Code,Name from...

  • mysql查询优化 - 慢查询

    mysql查询速度优化思路 开启慢查询日志 查看导致阻塞的sql语句 重现场景, 单独测试 mysql 慢查询分析...

  • 2018-03-20

    MYSQL查询语句 MYSQL复杂操作语句 MYSQL多表查询方法 函数部分

  • DQL

    MySQL单表查询:目的:在MySQL管理软件中,可以通过SQL语句中的DQL语言来实现数据的分类:简单查询:如所...

  • MySql常用语句

    测试工作数据库语句是必备技能,以下是我总结出来的mysql基础语句 创建数据库 create database ...

  • MySQL慢查询设置

    linux下开启mysql慢查询,分析查询语句

  • sql查询语句

    1.背景:sql语句也是测试人员的必备技能之一,看了个视频,大概的意思就是把要查询的语句拆分成一个一个的简单查询,...

  • mysql json 查询

    mysql json 查询 MySQL 5.7新增对JSON支持 1. 普通 json 查询 数据 查询语句 数...

  • mysql慢查询语句分析

    如何查找mysql中查询比较慢的语句mysqldumpslow分析慢查询语句 一: 查看Mysql是否开启了慢查...

  • SQL之WHERE语句

    SQL语句是数据库查询语句,可以应用在各种数据库操作软件中,比如Mysql,Oracle,因此SQL语句学一套就基...

网友评论

      本文标题:软件测试必备MySQL语句查询

      本文链接:https://www.haomeiwen.com/subject/hvylmqtx.html