Home >Database >Mysql Tutorial >How to use the error function floor() function and rand() function together in Mysql

How to use the error function floor() function and rand() function together in Mysql

王林
王林forward
2023-05-26 22:59:081847browse

    1. Floor function

    1.1 The function of floor function

    The function of floor() function is to return the maximum value that is less than or equal to this value. Integer

    Example: select floor(1.1) from qs_ad_category

    The result of the above query statement is 1. Since the maximum integer smaller than 1.1 is 1, the result is 1

    How to use the error function floor() function and rand() function together in Mysql

    Note: Limitations of the floor() function: mysql 5.0 and above

    2. rand() function

    2.1 The role of rand() function

    The role of the rand() function: Get a random floating point number (a decimal less than 0), while rand(0) gets a fixed decimal value

    Example: select rand() from qs_ad_category ;

    The result is a random floating-point decimal: 0.7450851357961866

    How to use the error function floor() function and rand() function together in Mysql

    ##3. The floor() function cooperates with the rand() function

    3.1 The use of two combined functions

    Since the rand() function obtains a floating point number less than 1, that is, for example, 0.7450851357961866 in the above result

    Floor() function rounds down the value inside the parentheses to the nearest integer that is less than or equal to it, and displays the result.. For example, the result of rand() above is 0.7450851357961866, then the maximum integer is "0", so:

    select floor(rand(0)) from qs_ad_category The result value is "0".

    If it is rand()*2, the rand() result may be greater than 1, then combined with the floor() function, the final value may be 1

    select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables

    4. Use the floor() function Mainly error injection

    4.1 Components of error injection

    floor() Accurately speaking, error injection should be floor, count, group by conflict error, count(*), rand() , group by are indispensable

    4.2 Error injection component analysis

    count() function: counting function, a function used to calculate the sum of data, this function has only one result set.

    floor() function rand() function: Get the integer value of 0 or 1

    group by function: When grouping data, it will first check whether the value exists in the virtual table, no If it exists, insert it; if it exists, count() will be incremented by 1. When using group by, floor(rand(0)2) will be executed once. If there is no record in the virtual table, it will be executed again when inserting into the virtual table.

    4.3 Display error injection

    使用报错获取当前用户信息
    select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x

    The above is the detailed content of How to use the error function floor() function and rand() function together in Mysql. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete