Advanced database · How to add random data to the data that is not in all user data-How to add avatar data for Dragonfly Q system users without avatars-Yacao Technology kir

Advanced database · How to add random data to the data that is not in all user data-How to add avatar data for Dragonfly Q system users without avatars-Yacao Technology kir

This content is mainly used for learning. The avatar is just an example field, which can be applied to other aspects.

Problem background:

The Dragonfly q Ultimate Edition automatically assigns user accounts and logs in based on mobile device information, skipping the step of user registration and uploading avatars, so a large number of users do not have avatars.

 

At this point, you need to add random avatars to these users and organize the following execution statements:

update users
set avatar='http://qingtingcun.youyacao.com/qiniu_202110270837150713870048.png'
where id IN(
select A.* from(select id from users where avatar='' order by rand() limit 10) AS A
);

This statement is to randomly find 10 items without avatar each time and update them to the specified avatar address:

http://qingtingcun.youyacao.com/qiniu_202110270837150713870048.png

Then if we want to randomly update several different avatars then the code is

update users
set avatar='图片1'
where id IN(
select A.* from(select id from users where avatar='' order by rand() limit 10) AS A
);
update users
set avatar='图片2'
where id IN(
    select A.* from(select id from users where avatar='' order by rand() limit 10) AS A
);
update users
set avatar='图片3'
where id IN(
    select A.* from(select id from users where avatar='' order by rand() limit 10) AS A
);

And so on, it is randomly updated to these three avatars, and so on, if you put a few more avatars and execute it a few times, it will be ok soon.

 

Effect

 

Execute it several times until it prompts that 0 lines are affected, indicating that all users have added avatars.

 

Guess you like

Origin blog.csdn.net/dujiangdu123/article/details/125909889