MySQL Learning 18: operator and function numeric operators and functions, comparison operators and functions, date-time functions

Source: Internet
Author: User
Tags integer division

numeric operators and functions

Some of the common numeric functions are the following:


(1) numeric operator The common numeric operators for MySQL databases are: + 、-、 * 、、、%, and so on. Here we will not enumerate, just to see two examples:

SELECT 3+4;

SELECT 3%4;


(2) in one rounding and one rounding

SELECT ceil (3.01);

SELECT floor (3.99);

(3) integer Division

SELECT 3/4;

SELECT 3 DIV 4;


(4) Take the remainder (modulo) SELECT 5% 3;

SELECT 5 MOD 3;


(5) Power Operation SELECT 5.3 MOD 3;

SELECT POWER (3,3);


(6) Rounding

SELECT ROUND (3.652,2);

SELECT ROUND (3.652,1);

SELECT ROUND (3.652,0);


(7) digital interception SELECT TRUNCATE (125.89,1);

SELECT TRUNCATE (125.89,0);

SELECT TRUNCATE (125.89,-1);


comparison operators and functions

Common comparison operators and functions:


(1) [not] within the range

SELECT between 1 and;

SELECT between 1 and 22;

SELECT between 1 and 22;


(2) [not] within the scope of the list SELECT Ten in (5,10,15,20);

SELECT in (5,10,15,20);


(3) [not] empty

SELECT null is null;

SELECT ' is NULL;

SELECT 0 is NULL;


(4)[not] empty in query statement

SELECT * FROM Test WHERE first_name is NULL;

SELECT * FROM Test WHERE first_name are not NULL;


Date-time functions

Commonly used date-time functions:


(1) Current date and time and current date and current time

SELECT now ();

SELECT curdate ();

SELECT Curtime ();


(2) Date change

SELECT date_add (' 2016-5-1 ', INTERVAL);

SELECT date_add (' 2016-5-1 ', INTERVAL-23 Day);

SELECT date_add (' 2016-5-1 ', INTERVAL 3 WEEK);


(3) Date difference and date formatting

SELECT DATEDIFF (' 2016-5-1 ', ' 2016-5-23 ');

SELECT DATEDIFF (' 2016-5-15 ', ' 2016-5-3 ');

SELECT date_format (' 2016-5-2 ', '%m/%d/%y ');


MySQL Learning 18: operator and function numeric operators and functions, comparison operators and functions, date-time functions

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.