V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
baiduyixia
V2EX  ›  问与答

求打乱排序的 sql 语句

  •  
  •   baiduyixia · May 30, 2023 · 1595 views
    This topic created in 1075 days ago, the information mentioned may be changed or developed.

    mysql ,a 表的字段 b 里面是一组数字,数字间用符号|隔离,比如 1 | 3 | 4 | 9 ,请问 sql 如何将字段 b 里面的 数字顺序随机打乱替换上去,谢谢

    4 replies    2023-05-31 09:14:34 +08:00
    urnoob
        1
    urnoob  
       May 30, 2023 via Android
    写个存储过程
    游标遍历每一行
    对 b 列值做分割
    随机拼
    update
    最后记得
    commit
    japeth
        2
    japeth  
       May 30, 2023
    取出来 程序处理更方便吧
    NauxLiu
        3
    NauxLiu  
       May 30, 2023
    理论上可以将 b 字段 split 开然后列转行,再 order by rand , 最后在 group concat 起来行转列。但是性能肯定是灾难性的。
    makelove
        4
    makelove  
       May 31, 2023
    这种问题一般是 chatgpt 的拿手好戏,我碰到这类边界很确定的都是直接扔 gpt 回来几乎不用改
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1501 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 17:06 · PVG 01:06 · LAX 10:06 · JFK 13:06
    ♥ Do have faith in what you're doing.