插入随机连接 Select 查询
Insert random Concate Select Query
我正在尝试获取随机行,9 列中只有 4 列,连接不同的行,然后将它们插入 table
例如:
test 1 9
test2 2 5
test3 3 6
我想随机 select 3 行中的 2 行
将 test2 和 test3 连接到 test2、test3
并插入 "test2, test3" 2+3(5) 5+6(11)
分为 3 个不同的列。
这完全有可能吗?能达到什么程度?
最好的问候
如果我没听错的话,你可以在子查询中随机 select 两行,然后在外部查询中聚合。
假设您的 table 的列是 tid
、val_1
和 val_2
:
select group_concat(tid) col_1, sum(val_1) val1, sum(val_2) val_2
from (select * from mytable order by rand() limit 2) t
您可以轻松地将其转换为 insert
语句:
insert into mytable (tid, val_1, val_2)
select ... -- the above query
我正在尝试获取随机行,9 列中只有 4 列,连接不同的行,然后将它们插入 table
例如:
test 1 9
test2 2 5
test3 3 6
我想随机 select 3 行中的 2 行 将 test2 和 test3 连接到 test2、test3 并插入 "test2, test3" 2+3(5) 5+6(11) 分为 3 个不同的列。
这完全有可能吗?能达到什么程度? 最好的问候
如果我没听错的话,你可以在子查询中随机 select 两行,然后在外部查询中聚合。
假设您的 table 的列是 tid
、val_1
和 val_2
:
select group_concat(tid) col_1, sum(val_1) val1, sum(val_2) val_2
from (select * from mytable order by rand() limit 2) t
您可以轻松地将其转换为 insert
语句:
insert into mytable (tid, val_1, val_2)
select ... -- the above query