Table of Contents
1. Floor function
1.1 The function of floor function
2. rand() function
2.1 The role of rand() function
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

May 26, 2023 pm 10:59 PM
mysql floor() rand()

    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 of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Beginner's Guide to RimWorld: Odyssey
    1 months ago By Jack chen
    PHP Variable Scope Explained
    4 weeks ago By 百草
    Tips for Writing PHP Comments
    3 weeks ago By 百草
    Commenting Out Code in PHP
    3 weeks ago By 百草

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1509
    276
    How to set environment variables in PHP environment Description of adding PHP running environment variables How to set environment variables in PHP environment Description of adding PHP running environment variables Jul 25, 2025 pm 08:33 PM

    There are three main ways to set environment variables in PHP: 1. Global configuration through php.ini; 2. Passed through a web server (such as SetEnv of Apache or fastcgi_param of Nginx); 3. Use putenv() function in PHP scripts. Among them, php.ini is suitable for global and infrequently changing configurations, web server configuration is suitable for scenarios that need to be isolated, and putenv() is suitable for temporary variables. Persistence policies include configuration files (such as php.ini or web server configuration), .env files are loaded with dotenv library, and dynamic injection of variables in CI/CD processes. Security management sensitive information should be avoided hard-coded, and it is recommended to use.en

    How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment How to make PHP container support automatic construction? Continuously integrated CI configuration method of PHP environment Jul 25, 2025 pm 08:54 PM

    To enable PHP containers to support automatic construction, the core lies in configuring the continuous integration (CI) process. 1. Use Dockerfile to define the PHP environment, including basic image, extension installation, dependency management and permission settings; 2. Configure CI/CD tools such as GitLabCI, and define the build, test and deployment stages through the .gitlab-ci.yml file to achieve automatic construction, testing and deployment; 3. Integrate test frameworks such as PHPUnit to ensure that tests are automatically run after code changes; 4. Use automated deployment strategies such as Kubernetes to define deployment configuration through the deployment.yaml file; 5. Optimize Dockerfile and adopt multi-stage construction

    How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts How to build an independent PHP task container environment. How to configure the container for running PHP timed scripts Jul 25, 2025 pm 07:27 PM

    Building an independent PHP task container environment can be implemented through Docker. The specific steps are as follows: 1. Install Docker and DockerCompose as the basis; 2. Create an independent directory to store Dockerfile and crontab files; 3. Write Dockerfile to define the PHPCLI environment and install cron and necessary extensions; 4. Write a crontab file to define timing tasks; 5. Write a docker-compose.yml mount script directory and configure environment variables; 6. Start the container and verify the log. Compared with performing timing tasks in web containers, independent containers have the advantages of resource isolation, pure environment, strong stability, and easy expansion. To ensure logging and error capture

    How to build a log management system with PHP PHP log collection and analysis tool How to build a log management system with PHP PHP log collection and analysis tool Jul 25, 2025 pm 08:48 PM

    Select logging method: In the early stage, you can use the built-in error_log() for PHP. After the project is expanded, be sure to switch to mature libraries such as Monolog, support multiple handlers and log levels, and ensure that the log contains timestamps, levels, file line numbers and error details; 2. Design storage structure: A small amount of logs can be stored in files, and if there is a large number of logs, select a database if there is a large number of analysis. Use MySQL/PostgreSQL to structured data. Elasticsearch Kibana is recommended for semi-structured/unstructured. At the same time, it is formulated for backup and regular cleaning strategies; 3. Development and analysis interface: It should have search, filtering, aggregation, and visualization functions. It can be directly integrated into Kibana, or use the PHP framework chart library to develop self-development, focusing on the simplicity and ease of interface.

    Advanced conditional query and filtering of relational data in MySQL/Laravel Advanced conditional query and filtering of relational data in MySQL/Laravel Jul 25, 2025 pm 08:39 PM

    This article aims to explore how to use EloquentORM to perform advanced conditional query and filtering of associated data in the Laravel framework to solve the need to implement "conditional connection" in database relationships. The article will clarify the actual role of foreign keys in MySQL, and explain in detail how to apply specific WHERE clauses to the preloaded association model through Eloquent's with method combined with closure functions, so as to flexibly filter out relevant data that meets the conditions and improve the accuracy of data retrieval.

    Optimizing MySQL for Financial Data Storage Optimizing MySQL for Financial Data Storage Jul 27, 2025 am 02:06 AM

    MySQL needs to be optimized for financial systems: 1. Financial data must be used to ensure accuracy using DECIMAL type, and DATETIME is used in time fields to avoid time zone problems; 2. Index design should be reasonable, avoid frequent updates of fields to build indexes, combine indexes in query order and clean useless indexes regularly; 3. Use transactions to ensure consistency, control transaction granularity, avoid long transactions and non-core operations embedded in it, and select appropriate isolation levels based on business; 4. Partition historical data by time, archive cold data and use compressed tables to improve query efficiency and optimize storage.

    MySQL Database Cost-Benefit Analysis for Cloud Migration MySQL Database Cost-Benefit Analysis for Cloud Migration Jul 26, 2025 am 03:32 AM

    Whether MySQL is worth moving to the cloud depends on the specific usage scenario. If your business needs to be launched quickly, expand elastically and simplify operations and maintenance, and can accept a pay-as-you-go model, then moving to the cloud is worth it; but if your database is stable for a long time, latency sensitive or compliance restrictions, it may not be cost-effective. The keys to controlling costs include selecting the right vendor and package, configuring resources reasonably, utilizing reserved instances, managing backup logs and optimizing query performance.

    Optimizing MySQL for Real-time Data Feeds Optimizing MySQL for Real-time Data Feeds Jul 26, 2025 am 05:41 AM

    TooptimizeMySQLforreal-timedatafeeds,firstchoosetheInnoDBstorageenginefortransactionsandrow-levellocking,useMEMORYorROCKSDBfortemporarydata,andpartitiontime-seriesdatabytime.Second,indexstrategicallybyonlyapplyingindexestoWHERE,JOIN,orORDERBYcolumns,

    See all articles