当前位置:网站首页>软件测试员必看!数据库知识mysql查询语句大全
软件测试员必看!数据库知识mysql查询语句大全
2022-07-30 04:26:00 【软件测试小仙女】
作为一名测试人,掌握数据库常用的操作不可缺少,下面就一段mysql 查询语句梳理几个相关语法知识。

本篇文章主要包括两方面内容
·常用的sql语法
·开发代码中如何和sql进行关联
案例代码:
`
select a.blastid,d.apptime,a.charge_approve,
a.blast_batch,
a.plan_blast_time,
a.exe_plan_id,
a.import_flag,
a.rig_type,.......
case when (select "count"(*) from bla_geology_info geo where a.blast_id=geo.blast_id and geo.delete_flag=0)>0
then 'true' else 'false'
END as isShowFlag
from bla_blast_info a
left join exe_plan_month b
on a.exe_plan_id = b.exe_plan_id
left join sys_user c
on a.dynamite_user = c.user_id
left join (select blast_id,isagree,idea,create_time as app_time from bla_charge_approve where delete_flag = '0') d
on a.blast_id = d.blast_id
WHERE a.blast_type = '1' AND a.blast_status > '3' AND a.blast_status < '8' AND a.charge_approve > '1' AND a.delete_flag = '0' ORDER BY cast(a.charge_approve as numeric) ASC , d.app_time DESC , a.create_time DESC
`
一 常用的sql语法
1.查询语句 select xxxx from 表名 ,表示从哪个表进行查询。其中select 后面内容以,分割。
2. select xxxx from 表名 别名,表示这个表用别名替代,如上个语句中的a,b,c等
3.case when then xx,else xxx ,end as isShowFlag表示符合when 条件执行 then 后面语句,否则执行else 后面语句,
eg 案例中case when (select "count"(*) from blageologyinfo geo where a.blastid=geo.blastid and geo.delete_flag=0)>0
then 'true' else 'false' 表示符合条件的爆破量进行上传
end as isShowFlag 起的查询语句别名,后续调用的时候 使用别名名称即可。
4.left join 左连接 ,表1左连接表2,以左为主,表示以表1为主,关联上表2的数据,查出来的结果显示左边的所有数据,然后右边显示的是和左边有交集部分的数据。

一句话的意思是 先取交集,再关联到左表。
引申整理出几个连接的常用含义及区分 ,如下表所示:

5.查询语句 select xxxx from 表名 where 查询条件
where 查询条件后面接所有你要查询的内容,用and连接,这里需要注意order by 使用
order by 1,2,3,4 ,先1排序,1相同的情况下按照2,3,4排序
6. cast ()数据类型转换函数,文中cast(a.charge_approve as numeric) 表示将字段charge_approve 转换为数字型,以前是字符类型,字符类型的字段不可以进行排序
7. a.exe_plan_id = b.exe_plan_id 表示 a表的exe_plan_id字段和b表的exe_plan_id 字段进行绑定,可以这么理解 只有两个表绑定后才能进行相关的查询操作。
总结通用模板:
Select 字段名1,字段名2 case when 条件 then 执行语句 else 执行语句 end as 别名 from 表名 别名 left join on 表连接(a.exe_plan_id = b.exe_plan_id)
Where 查询条件(d.app_time DESC)
二 开发代码中如何和sql进行关联
开发逻辑中有一个词‘mapper映射’,里面具体的实现不做过多赘述。
简单点的逻辑是:
用xml文件 将sql 语句的名称 和 实体名称一一映射,通过这种形式进行绑定,然后在代码中引用映射的文件名,从而实现数据查询。

上面我们通过一段sql 语句列举了 mysql 常用的语法,以及sql语句编写完成后 如何在代码中进行使用的。
最后:
可以到我的个人号:atstudy-js,可以免费领取一份10G软件测试工程师面试宝典文档资料。以及相对应的视频学习教程免费分享!其中包括了有基础知识、Linux必备、Mysql数据库、抓包工具、接口测试工具、测试进阶-Python编程、Web自动化测试、APP自动化测试、接口自动化测试、测试高级持续集成、测试架构开发测试框架、性能测试等。
这些测试资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!
边栏推荐
- Thinkphp 5.0.24变量覆盖漏洞导致RCE分析
- Drools (7): WorkBench
- 1. 获取数据-requests.get()
- Usage of exists in sql
- 函数的底层机制
- Atomic Guarantees of Redis Distributed Locks
- 小程序 wx.miniProgram.navigateTo 跳转地址不能是tabbar地址
- error: The following untracked working tree files would be overwritten by
- golang八股文整理(持续搬运)
- 【驱动】udev为USB转4串口的每个串口起别名
猜你喜欢

国内首家沉浸式高逼真元宇宙,希元宇宙正式上线

DAY17:弱口令的探测与测试

How does the Snapdragon 7 series chip perform?Reno8 Pro proves a new generation of God U

【C语言】程序环境和预处理

Eureka注册中心

unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)
![Advanced [C] array to participate in the function pointer](/img/00/67dd77463670c8ebd5d004dbe12549.jpg)
Advanced [C] array to participate in the function pointer

Pytorch framework learning record 3 - the use of Transform

MYSQL 唯一约束
![[SQL] at a certain correlation with a table of data update another table](/img/66/4dff4383509e5d25890d8a24720de6.png)
[SQL] at a certain correlation with a table of data update another table
随机推荐
cnpm installation steps
Many overseas authoritative media hotly discuss TRON: laying the foundation for the decentralization of the Internet
MYSQL unique constraint
C. Qualification Rounds(思维,特情)
The leap second that may cause the next "Millennium Bug" is boycotted by tech giants
Android Studio 实现登录注册-源代码 (连接MySql数据库)
Pytorch框架学习记录2——TensorBoard的使用
Go 学习笔记(84)— Go 项目目录结构
商品管理系统数据库设计--SQL Server
海外多家权威媒体热议波场TRON:为互联网去中心化奠定基础
RRU, BBU, AAU
js 操作在当前日期加减(天、周、月、年数)
unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)
Database Design of Commodity Management System--SQL Server
How to extract year, month and day data in date type in SQL Server
The first immersive and high-fidelity metaverse in China, Xiyuan Universe is officially launched
MySQL data query (subtotal and sorting)
Pytorch框架学习记录3——Transform的使用
获取本机IP和Request的IP
2.6归并排序