mysql 创建临时表和case语法的使用
- 创建一个临时表,表明叫做mytest,表的内容通过 select * from acctmy where gcode = ‘000454’ 获取。
create temporary table mytest(select * from acctmy where gcode = '000454' )
- 使用case when then else 进行查询。
select case
when code = 'c' then "this recode's type is c"
when code = 'm' then "this recode's type is m"
when code = 'e' then "this recode's type is e"
else "啥也不是"
end as
code ,no,custno,gcode from acctmy;
值得注意的是在case的语句块结束后要用end ,但是再end 后面可以加as 或者这是不加
- 再对比一下if … elseif…else…的使用 @myno是我定义的一个变量
if @myno <> '7300104 ' then
select "这是不等于";
elseif length(trim(@myno)) = 0 or @myno is null then
select "这是没有长度";
else
select "我草";
end if;
版权声明:本文为qq_41087623原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。