我有一个带2个表的SQLITE数据库。表格具有以下结构:
TABLE1 (about 2000000 records)
id|name|number1|number2|...|...
1|aaa |12.23 |43.17 |...|...
2|bbb |54.145 |77.23 |...|...
3|ccc |65.2345|13.234 |...|...
TABLE2 (about 1500000 records)
id|name|number1|number2
1|ddd |100.121|12.32
2|bbb |76.223 |11.45
3|eee |55.23 |32.1
我需要这样做:
最好和最快的方法是什么?
我可以使用SQLITE编辑器吗?哪个?
答案 0 :(得分:0)
可能(未经测试)的方式:
UPDATE TABLE1
SET
number1 = (SELECT COALESCE(MAX(TABLE2.number1), (CAST(ABS((RANDOM()%30)) AS INT)+1) / 100)
FROM TABLE2
WHERE TABLE2.name = TABLE1.name),
number2 = (SELECT COALESCE(MAX(TABLE2.number2), (CAST(ABS((RANDOM()%30)) AS INT)+1) / 100)
FROM TABLE2
WHERE TABLE2.name = TABLE1.name);
可以通过在name
和TABLE1
表格的TABLE2
列上创建索引来加速查询。
<强>参考强>:
sql: how to update table values from another table with the same user name? on SO