没有不值得去解决的问题,也没有不值得去学习的技术!

How to Update a MySQL 5.6 Field by Concatenating Other Fields on Windows 10 64

Decide to first remove the spaces in the team_code field, then execute the SQL to modify the avatar field. The SQL statement executes successfully

1. The final expected result is to modify the avatar in the player table, with its value being: /storage/web/app/player_avatar/GZHOU/579365.jpg, where GZHOU is the value of the current record’s team_code field and 579365 is the value of the current record’s code field, as shown in Figure 1

The final expected result is to modify the avatar in the player table, with its value being: /storage/web/app/player_avatar/GZHOU/579365.jpg, where GZHOU is the value of the current record's team_code field and 579365 is the value of the current record's code field
Figure 1

2. First, modify the avatar of a single record. The SQL statement executes successfully, as shown in Figure 2
UPDATE `kq_player` SET `avatar` = concat(‘/storage/web/app/player_avatar/’,`team_code`,’/’,`code`,’.jpg’) WHERE `code` = ‘389345’;

First, modify the avatar of a single record. The SQL statement executes successfully
Figure 2

3. After refreshing, check the execution result. The avatar of the record with code 389345 has the value: /storage/web/app/player_avatar/GZHOU/389345.jpg. The modification is successful and meets expectations, as shown in Figure 3

After refreshing, check the execution result. The avatar of the record with code 389345 has the value: /storage/web/app/player_avatar/GZHOU/389345.jpg. The modification is successful and meets expectations
Figure 3

4. Check the records before modifying all records; the avatar is empty, as shown in Figure 4

Check the records before modifying all records; the avatar is empty
Figure 4

5. Prepare to modify the avatar of all records by removing the WHERE condition. The SQL statement executes successfully, as shown in Figure 5
UPDATE `kq_player` SET `avatar` = concat(‘/storage/web/app/player_avatar/’,`team_code`,’/’,`code`,’.jpg’);

Prepare to modify the avatar of all records by removing the WHERE condition. The SQL statement executes successfully
Figure 5

6. Check the records after modifying all records; the avatar is no longer empty. The modification is successful and meets expectations, as shown in Figure 6

Check the records after modifying all records; the avatar is no longer empty. The modification is successful and meets expectations
Figure 6

7. Search the avatar field to check whether it contains spaces, as shown in Figure 7

Search the avatar field to check whether it contains spaces
Figure 7

8. The SQL statement executes successfully, and some records indeed contain spaces, as shown in Figure 8
/storage/web/app/player_avatar/LIFAN /974218.jpg

The SQL statement executes successfully, and some records indeed contain spaces
Figure 8

9. Decide to first remove the spaces in the team_code field, then execute the SQL to modify the avatar field. The SQL statement executes successfully, as shown in Figure 9
UPDATE `kq_player` SET `team_code` = replace(`team_code`,’ ‘,”);
UPDATE `kq_player` SET `avatar` = concat(‘/storage/web/app/player_avatar/’,`team_code`,’/’,`code`,’.jpg’);

Decide to first remove the spaces in the team_code field, then execute the SQL to modify the avatar field. The SQL statement executes successfully
Figure 9

10. Search the avatar field to check whether it contains spaces; zero rows are returned, as shown in Figure 10

Search the avatar field to check whether it contains spaces; zero rows are returned
Figure 10

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系