我要求Microsoft SQL Server和PostgreSQL的类似的问题的随机行复制多个值。在那里工作的解决方案不适用于MySQL。MySQL的:从另一个表
我有两个表,stuff
和nonsense
。我想多个值从随机排nonsense
在stuff
复制到每一行。当然,会有重复。
STUFF
+----+---------+-------------+--------+
| id | details | data | more |
+====+=========+=============+========+
| 1 | one | (null) | (null) |
| 2 | two | (null) | (null) |
| 3 | three | (null) | (null) |
| 4 | four | (null) | (null) |
| 5 | five | (null) | (null) |
| 6 | six | (null) | (null) |
+----+---------+-------------+--------+
NONSENSE
+----+---------+-------------+
| id | data | more |
+====+=========+=============+
| 1 | apple | accordion |
| 2 | banana | banjo |
| 3 | cherry | cor anglais |
+----+---------+-------------+
我希望能够复制到stuff
表的东西,如:
UPDATE stuff SET data=?,more=?
FROM ?
我想获得像下面这样:
+-----+----------+---------+-------------+
| id | details | data | more |
+=====+==========+=========+=============+
| 1 | one | banana | banjo |
| 2 | two | apple | accordion |
| 3 | three | apple | accordion |
| 4 | four | cherry | cor anglais |
| 5 | five | banana | banjo |
| 6 | six | cherry | cor anglais |
+-----+----------+---------+-------------+
这里是一个小提琴其中工程对PostgreSQL:如果它是一个单一VA http://sqlfiddle.com/#!17/313fb/8
lue,我可以使用相关的子查询,但对于来自同一行的多个值无法正常工作。
较新的PostgreSQL有从相关子查询复制到多列的能力。 SQL Server的OUTER APPLY
子句允许FROM子句中的子查询相关联。这两种方法都不适用于MySQL。
我怎样才能在另一个表从随机行复制多个值吗?
显示预期结果请 – scaisEdge
@scaisEdge请参阅编辑。小提琴在这里:http://sqlfiddle.com/#!17/313fb/8 – Manngo