当前位置:网站首页>数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
2022-07-25 22:02:00 【~央千澈~】
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
本内容主要用于学习,头像只是举例的一个字段,可以应用在其他方面,举一反三
问题背景:
蜻蜓q旗舰版是根据手机设备信息自动分配用户账号并登陆,跳过了用户注册上传头像步骤,因此大量用户没有头像,

此时需要给这些用户添加上随机的头像整理以下运行语句:
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
);这段语句是每次随机找出10条没有头像的进行更新为指定头像地址:
http://qingtingcun.youyacao.com/qiniu_202110270837150713870048.png
那么如果我们要随机更新不同的几个头像那么代码则为
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
);诸如此就是随机更新为这三个头像,以此类推,如果多放几个头像多执行几次很快就ok了。

效果

多执行几次,直到提示有0行被影响说明所有用户都已经加上头像了。

边栏推荐
- Acwing 866. determining prime numbers by trial division
- 【GO基础02】第一个程序
- Ansible+cronab batch deployment patrol
- Whether the five distribution methods will produce internal fragments and external fragments
- C语言:随机生成数+选择排序
- The technical aspects of ByteDance are all over, but the result is still brushed. Ask HR why...
- Simple use of protobuf
- I/o case practice
- [51nod1676 undirected graph isomorphism] undirected graph hash [easy to understand]
- Redis基础2(笔记)
猜你喜欢

成为比开发硬气的测试人,我都经历了什么?

【饭谈】如何设计好一款测试平台?

jenkins+SVN配置

手机端微信发朋友圈功能测试点总结

Children's programming electronic society graphical programming level examination scratch level 1 real problem analysis (judgment question) June 2022

6-18漏洞利用-后门连接

虚拟内存与磁盘

Origen foundation officially launched $ogy stacking, leading a new round of ecological benefits

Animation curves are used every day. Can you make one by yourself? After reading this article, you will!

ansible+Crontab批部署巡检
随机推荐
jsp九大内置对象
【leetcode天梯】链表 · 876 查找链表中间结点
[hand tear STL] BitSet (bitmap), bloom filter
自动化测试岗花20K招人,到最后居然没一个合适的,招两个应届生都比他们强吧
dovecot 设置邮箱quota
Simple use of protobuf
【测开方法论】测开平台pk心得-抉择
c sqlite ... ...
YUV420 YUV420sp 图像格式「建议收藏」
[redis underlying parsing] linked list type
2 lines of code to generate a solid desktop background
Composition of dog food
JSP novice
Uninstall NPM and install NPM_ Use 'NPM uninstall' to uninstall the NPM package 'recommended collection'
若依如何解决导出使用下载插件出现异常?
【饭谈】如何设计好一款测试平台?
The technical aspects of ByteDance are all over, but the result is still brushed. Ask HR why...
别投了,软件测试岗位饱和了...
C语言:随机生成数+冒泡排序
[dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)