补充:
临时表(子查询)
指定映射
条件:
– case when … then …
三元运算:
if (isnull(xx),0,1)
上下连表:
左右连表:join
上下连表:union(自动去重) union all(不去重)
select id,name from tb11
union all
select id,name from tb11
视图:
在子查询中,给某个查询语句(查询的临时表)设置别名,日后方便使用。
虚拟出来的表,并非真正的物理表
创建视图:create view 视图名称 as SQL语句;
修改视图:alter view 视图名称 as SQL语句;
删除视图:drop view 视图名称;
触发器:
对某个表进行【增/删/改】操作时,可以使用触发器自定义关联行为。
函数:
性能低,有索引的列用函数的话索引不管用。
内置函数:
时间格式化
select data_format(ctime,"%Y-%m"),count(1) from blog group by data_format(ctime,"%Y-%m");
自定义函数(有返回值):
delimiter\\
create function f1(
i1 int,
i2 int
)returns int
begin
decl