MySQL a field inserts the random number (inserts the random number to the MySQL database) _mysql

Source: Internet
Author: User
Tags rand

Common code

 
Update ' table name ' Set click=click*0.01 where classid= ' 2 ' and click>2000

We often encounter random problems, and here's a way to solve random numbers.

When constructing test data, we need to insert random data into the test table. The method for constructing test data is as follows, with update as an example

Step 1: The SQL function for the random number is rand (), and Rand () produces a decimal between 0-1.

Step 2: *10 rand ()

A decimal number between 1-10 is generated and can be converted using Ceil.

Step 3: Use cast to do type conversion

The use of cast is as follows:

Cast (value as type)

Binary, with the effect of BINARY prefix: BINARY

Character type, with parameters: CHAR ()

Dates: Date

Time: Times

Date-time: DATETIME

Floating point numbers: DECIMAL

Integer: Signed

unsigned integer: UNSIGNED

SELECT CAST (rand () *10 as signed) as Rand

Step 4: Run the SQL statement

UPDATE Storm_effect_info S SET

S.FHTP = (SELECT CAST (rand () *10 as signed) as RAND) WHERE s.id = 13

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.