当前位置:网站首页>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!
边栏推荐
- 【MySQL系列】-B+树索引和HASH索引有什么区别
- Database Design of Commodity Management System--SQL Server
- WEB penetration of information collection
- QT(39)-vs开发qt程序提示无法打开源文件
- 【翻译】Envoy Fundamentals,这是一个培训课程,使人们能够更快地采用Envoy Proxy。...
- Boss Rush (二分答案 + 状压DP)
- Become a qualified cybersecurity, do you know this?
- See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
- Reverse Theory Knowledge 3 [UI Modification]
- Pytorch framework to study record 6 - the torch. Nn. The Module and the torch nn. Functional. The use of conv2d
猜你喜欢
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
@ WebServlet annotations (Servlet annotations)
Android Studio 实现登录注册-源代码 (连接MySql数据库)
Advanced [C] array to participate in the function pointer
Atomic Guarantees of Redis Distributed Locks
Drools (7): WorkBench
Thymeleaf简介
Redis "super explanation!!!!!!"
Detailed transport layer
Discourse 自定义头部链接(Custom Header Links)
随机推荐
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
[SQL] at a certain correlation with a table of data update another table
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Based on all volunteers - H and D1 XR806 rare plant monitoring device
Android Studio 实现登录注册-源代码 (连接MySql数据库)
swagger使用教程——快速使用swagger
GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
数据库概论 - MySQL的简单介绍
[MRCTF2020]Hello_ misc
山西省第二届网络安全技能大赛(企业组)部分赛题WP(七)
Pytorch framework learning record 7 - convolutional layer
RRU, BBU, AAU
2021山东省网络搭建与应用赛项试题
Arrays and Structures
Thinkphp 5.0.24变量覆盖漏洞导致RCE分析
VUX Datetime 组件compute-days-function动态设置日期列表
文件系统二
Charles replaces the interface response information
What is CDH/CDP?
权值线段树+线段树分裂/合并+CF1659D