select 字段1,字段2...... from (select......from......)
例如:select name,timestampdiff(year,date_format(concat_ws('-',left(cjgz_date,4),right(cjgz_date,2),'01'),'%Y-%m-%d'),sysdate()) as gl from hmc;
>> 创建临时表
select A.字段1,A.字段2 from (select......from......) tl_name(A) where ....
select gl from (select name,timestampdiff(year,date_format(concat_ws('-',left(cjgz_date,4),right(cjgz_date,2),'01'),'%Y-%m-%d'),sysdate()) as gl from hmc) A
>> case 流程控制语句,并将该流程控制语句结果赋值给指定字段:
casewhen 条件1 then 语句1when 条件2 then 语句2......else 其他语句end
04