Several MySQL functions commonly used in projects

Source: Internet
Author: User
Tags month name mysql functions

1.find_in_set function
Find_in_set (str,strlist); STR is a string strlist is a string list--a string that has more than one child chain "," separated by
There are a number of situations:
Null find_in_set (NULL, "A.STR") returns NULL when NULL or strlist is NULL
B. If the first argument is a constant string and the second is a type set column, the Find_in_set () function is optimized to use the bit calculation
C.str not in strlist or empty string returns 0 str with "," will error
Select Find_in_set (' 2 ', ' + '); return 2
Select Find_in_set (' 6 ', ' 1 '); Returns 0
SELECT Find_in_set (' B ', ' a,b,c,d ') str is b in the second position in strlist so return 2

D. Special case: SELECT * from user where Find_in_set (ID, "1,3,4,5,8");
Similar to select * from user where ID in (1,3,4,5,8);
2.date_format (Date,format) formatted date
%a Abbreviated Week name
%b Abbreviated month name
%c month, numeric
%d days of the month with English prefixes
%d months of the day, value (00-31)
%e Month Day, value (0-31)
%f μs
%h hours (00-23)
%h hours (01-12)
%i hours (01-12)
%i min, numeric (00-59)
Day of the%j year (001-366)
%k hours (0-23)
%l hours (1-12)
%m Month Name
%m month, value (00-12)
%pam or PM
%r time, 12-hour (Hh:mm:ss AM or PM)
%s seconds (00-59)
%s seconds (00-59)
%t time, 24-hour (HH:MM:SS)
%u week (00-53) Sunday is the first day of the week
%u week (00-53) Monday is the first day of the week
%v Week (01-53) Sunday is the first day of the week, with%x
%v Week (01-53) Monday is the first day of the week, with%x
%w Week Name
%w Day of the week (0= Sunday, 6 = Saturday)
%x year, of which Sunday was the first day of the week, 4-bit, with%V used
%x year, of which Monday was the first day of the week, 4-bit, with%v used
%y year, 4 people
%y year, 2 people
3.from_unixtime and Unix_timestamp are the opposite time functions
From_unixtime is to convert the specified format of seconds to a date SELECT from_unixtime (1511280000, '%y year%m month%d ') November 22, 2017
Unix_timestamp is the conversion of a date into seconds SELECT unix_timestamp (' 2017-11-22 '); 1511280000

Several MySQL functions commonly used in projects

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.