当前位置:网站首页>A must see for software testers!Database knowledge MySQL query statement Daquan
A must see for software testers!Database knowledge MySQL query statement Daquan
2022-07-30 04:30:00 【software testing fairy】
As a tester, it is indispensable to master the common operations of the database. The following is a mysql query statement to sort out some related grammar knowledge.

This article mainly includes two aspects
·Commonly used sql syntax
·How to associate with sql in the development code
Case code:
`
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_approveas numeric) ASC , d.app_time DESC , a.create_time DESC
`
A commonly used sql syntax
1. The query statement select xxxx from table name indicates which table to query from.The content after select is divided by .
2. select xxxx from table name alias, indicating that this table is replaced by an alias, such as a, b, c, etc. in the previous statement
3.case when then xx, else xxx, end as isShowFlag means that the statement after then is executed when the condition is met, otherwise the statement after the else is executed,
eg case when (select "count"(*) from blageologyinfo geo where a.blastid=geo.blastid and geo.delete_flag=0)>0
then 'true' else 'false' means that the qualified blasting amount will be uploaded
end as isShowFlag is the alias of the query statement, and the alias name can be used for subsequent calls.
4.left join left join, table 1 left join table 2, left as the main, indicating that table 1 is the main, associated with the data in table 2, the result of the search shows all the data on the left, and then the data displayed on the rightis the data that intersects with the left.

The meaning of a sentence is to take the intersection first, and then associate it to the left table.
Extended and sorted out the common meanings and distinctions of several connections, as shown in the following table:

5. Query statement select xxxx from table name where query condition
Where the query condition is followed by all the content you want to query, connect with and, here you need to pay attention to the use of order by
order by 1, 2, 3, 4, sort 1 first, if 1 is the same, sort by 2, 3, 4
6. cast () data type conversion function, in the text cast(a.charge_approve as numeric) means to convert the field charge_approve to numeric type, which used to be character type, and character type fields cannot be sorted
7. a.exe_plan_id = b.exe_plan_id means that the exe_plan_id field of table a and the exe_plan_id field of table b are bound. It can be understood that only after the two tables are bound, related query operations can be performed.
Summary of common templates:
Select field name 1, field name 2 case when condition then execute statement else execute statement end as alias from table name alias left join on table join (a.exe_plan_id = b.exe_plan_id)
Where query condition (d.app_time DESC)
Second, how to associate with sql in the development code
There is a word 'mapper mapping' in the development logic, and the specific implementation in it will not be repeated too much.
The simple logic is:
Use the xml file to map the name of the sql statement and the entity name one by one, bind in this form, and then reference the mapped file name in the code to realize data query.

Above we listed the common syntax of mysql through a sql statement, and how to use it in the code after the sql statement is written.
Last:
You can go to my personal number: atstudy-js, you can get a free 10G software test engineer interview collection document.And the corresponding video learning tutorials are shared for free!It includes basic knowledge, Linux essentials, Mysql database, packet capture tools, interface testing tools, advanced testing-Python programming, Web automated testing, APP automated testing, interface automated testing, advanced continuous integration testing, testing architecture development testingFramework, performance testing, etc.
These test materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey, and I hope it can also help you!
边栏推荐
- [Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
- 海外多家权威媒体热议波场TRON:为互联网去中心化奠定基础
- 【C语言】程序环境和预处理
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- Install MySQL Database on Kylin V10 Operating System
- [MRCTF2020]Hello_ misc
- sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
- SQLSERVER merges subquery data into one field
- Simple experiment with BGP
- [The Mystery of Cloud Native] Cloud Native Background && Definition && Detailed explanation of related technologies?
猜你喜欢
Go 学习笔记(84)— Go 项目目录结构

2.4希尔排序

PyG搭建R-GCN实现节点分类

cnpm installation steps

state space representation

Charles replaces the interface response information

Arrays and Structures

Pytorch framework learning record 5 - the use of DataLoader

Chapter8 Support Vector Machines

Based on all volunteers - H and D1 XR806 rare plant monitoring device
随机推荐
基于OpenCV实现的图像拼接(配准)案例
SQL Server data type conversion function cast () and convert () explanation
Unity3D Application模拟进入前后台及暂停
phpoffice edit excel document
Pytorch framework learning record 7 - convolutional layer
A brief introduction to the SSM framework
Advanced [C] array to participate in the function pointer
[Driver] udev sets the owner, group and permissions after GPIO is loaded
High Concurrency Framework Disruptor
MYSQL 唯一约束
【Untitled】
The VUX Datetime component compute-days-function dynamically sets the date list
MySql 怎么查出符合条件的最新的数据行?
Roperties class configuration file & DOS to view the host network situation
VUX Datetime 组件compute-days-function动态设置日期列表
2.6基数排序(桶排序)
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Become a qualified cybersecurity, do you know this?
Based on all volunteers - H and D1 XR806 rare plant monitoring device
WEB 渗透之信息收集