一些关键字
起别名 as
去重复 distinct
条件查询 where
模糊查询:
(like +’%_s’)
between and
in
isnull / is not null
排序: order by
常见函数
1.单行函数
(1)字符函数
length(str) , concat(str.str..),
upper(str), lower(str) ,
substr(str,int pos) ,substr(str, pos , len)
instr (str, substr)
trim("a" from "aabbaa") or trim(" asd ")
lpad(str1被填入,int n , str填入) rpad()
replace(str,str1,str2)
(2)数学函数
round(float,int length)
ceil(int n ) . floor(int n)
TRUNCATE(float N,INT I ) , TRUNCATE(1.123123,3 )
(3)日期函数
now(); curDate(); curTime();
Year(now()); Year('1998-1-1') ;
Month() MonthName();
str_to_datae('9-13-1999', '%m-%d-%Y')
date_format(now(),'%Y-%m-%d')
%Y:年(四位) %y 年(2位) %m 月(01- 12) %c 月(1-12)
%d 日 , %H :小时(24) ,%h 小时:(12) , %o 分钟 , %s 秒
(4)其他函数
Version() ; DataBase() , User()
(5) if 和case
if(条件,ture返回值,false返回值)
case 分为有参数和无参数
1.
CASE input_expression
WHEN when_expression THEN result_expression
ELSE else_result_expression
END
2.
CASE
WHEN Boolean_expression THEN result_expression
WHEN Boolean_expression THEN result_expression
ELSE else_result_expression
END
2.分组函数
sum(),avg() , max(), min() ,count()
查询
select xx,xx
from ()
left/right/full (outer) join ---- on(条件)
where 。。。
group by ()
having ()
order by ()
limint offset,size
子查询
select 搭配 (标量)
where/having (标量 = < > <> 等)
(列 in/not in , any/some , all)
(行 (A,B)=(select … ))
from 搭配 (表)
exists 搭配 (表) 返回一个bool 值
Union 、 Union ALL
要求: 1.对其 2.个数相等