我有一个200k行的mysql表和一个空值的列,我喜欢用1到10,000的随机数填充这个列。
我不知道是否可能有这样的查询:
UPDATE 'videos'
SET 'views' = rand(1,10000)
答案 0 :(得分:9)
RAND()
生成0到1的随机浮点值。你能试试吗?
Update videos set views = CAST(RAND() * 10000 AS UNSIGNED)
答案 1 :(得分:3)
试试这个。它可以生成1到10000之间的随机数。
UPDATE videos
SET views = FLOOR(rand() * 10000) + 1;
答案 2 :(得分:0)
或者这个:
UPDATE videos SET views = FLOOR(1 + rand() * 10000 );
答案 3 :(得分:0)
使用随机电话号码更新表记录
DECLARE @OrderDetailID INT
DECLARE @Phone VARCHAR(100)
DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT DISTINCT
OrderDetailID
FROM dbo.OrderDetailTBL
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @OrderDetailID
WHILE @@FETCH_STATUS = 0
BEGIN
--Do something with Id here
SET @Phone = '(' + CONVERT(VARCHAR(3), CONVERT(NUMERIC(3, 0), RAND()
* 899)) + ') ' + CONVERT(VARCHAR(3), CONVERT(NUMERIC(3, 0), RAND()
* 899)) + '-' + CONVERT(VARCHAR(4), CONVERT(NUMERIC(4, 0), RAND()
* 8999))
UPDATE dbo.OrderDetailTBL
SET ShippingPhone = @Phone
WHERE OrderDetailID = @OrderDetailID
FETCH NEXT FROM MY_CURSOR INTO @OrderDetailID
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
答案 4 :(得分:0)
如果您想使用某个范围之间的随机数更新一列并且具有-Ve类型,则可以使用以下代码:
addons: apt: packages: oracle-java8-set-default