regexp
正则表达式trim
修剪replace
替换ceiling
最高限度year
年month
月day
日hour
小时minute
分钟second
秒current
当前的date
日期time
时间now
如今week
星期version
版本加 +正则表达式
select bookprice,bookprice+10 from book;
复制代码
减 -sql
select bookprice,bookprice-10 from book;
复制代码
乘 *函数
select bookprice,bookprice*10 from book;
复制代码
除 /post
select bookprice,bookprice/10 from book;
复制代码
求余/取模 %ui
select bookprice,bookprice%10 from book;
复制代码
大于/小于spa
SELECT bookname, bookprice FROM book WHERE bookprice > 20;
复制代码
SELECT bookname, bookprice FROM book WHERE bookprice < 20;
复制代码
不等设计
SELECT bookname, bookprice FROM book WHERE bookprice <> 20;
复制代码
SELECT bookname, bookprice FROM book WHERE bookprice != 20;
复制代码
正则code
select bookname,bookname REGEXP '^j',bookauthor,bookauthor REGEXP '红$',bookpublisher,bookpublisher REGEXP '.+出版社' from book;
复制代码
select * from book where bookpublisher REGEXP '.+[0-9]$';
复制代码
&& andregexp
select * from book where borrowsum > 5 and borrowsum < 30;
复制代码
select * from book where borrowsum > 5 && borrowsum < 30;
复制代码
! notcdn
select * from book where not borrowsum = 30;
复制代码
select * from book where borrowsum != 30;
复制代码
select * from book where borrowsum <> 30;
复制代码
|| or
select * from book where borrowsum <= 5 or borrowsum >= 30;
复制代码
select * from book where borrowsum <= 5 || borrowsum >= 30;
复制代码
这四个语句, 结果同样
select * from book where borrowsum > 5 and borrowsum < 30;
复制代码
select * from book where borrowsum > 5 && borrowsum < 30;
复制代码
select * from book where not( borrowsum <= 5 or borrowsum >= 30);
复制代码
select * from book where not( borrowsum <= 5 || borrowsum >= 30);
复制代码
left(s,n)/right(s,n)
select bookname,left(bookname,2) from book;
复制代码
select bookname,right(bookname,2) from book;
复制代码
concat()/concat_ws()
select bookid,bookname,bookauthor,bookpublisher,bookprice,CONCAT(bookid,bookname,bookauthor,bookpublisher,bookprice) as 详情1,CONCAT_WS('_',bookid,bookname,bookauthor,bookpublisher,bookprice) as 详情2 from book;
复制代码
trim()/ltrim(s)/rtrim(s)
select bookpublisher,trim(bookpublisher) 删除左右空格,ltrim(bookpublisher) 删除左空格,rtrim(bookpublisher) 删除右空格 from book;
复制代码
replace()
select bookname 替换前,replace(bookname,'设计','崩溃') 替换后 from book;
复制代码
substring()
select bookname, SUBSTRING(bookname,2,3) from book;
复制代码
now()
select now();
复制代码
curdate()/curtime()
select now(),CURRENT_DATE(),CURRENT_TIME(),curdate(),curtime();
复制代码
dayofweek(d)/dayofmonth(d)/dayofyear(d)
select now(),DAYOFWEEK(now()),DAYOFMONTH(now()),DAYOFYEAR(now()),WEEKDAY(now());
复制代码
hour(t)/minute(t)/second(t)
select now(),HOUR(now()),MINUTE(now()),SECOND(now());
复制代码
date_add()/date_sub()
select DATE_ADD(now(),interval 3 day);
复制代码
select DATE_SUB(now(),INTERVAL 7 MINUTE);
复制代码
datediff()
select DATEDIFF('2020-10-1',now());
复制代码
abs(x)
select abs(-789),abs(-123.666);
复制代码
floor(x)/ceiling(x)
select FLOOR(-2.3),CEILING(-2.3),FLOOR(9.9),CEILING(9.9);
复制代码
greatest()/least()
select GREATEST(1,2,3,4),LEAST(1,2,3,4);
复制代码
round(x)/truncate(x,y)
select round(3.4567),round(4.567),TRUNCATE(3.4567,3);
复制代码
rand()
select rand(),rand();
复制代码
sqrt(x)/mod(x,y)
select sqrt(64),sqrt(2),TRUNCATE(sqrt(2),3),mod(10,4);
复制代码
database()/user()/version()
select DATABASE(),user(),version();
复制代码
charset(str)/collation(str)
select charset('123'),COLLATION('123');
复制代码