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');
複製代碼