baiduyixia
V2EX  ›  问与答

求打乱排序的 sql 语句

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