声明变量
1.变量不能以数字作为开头
2.只能使用_或$符号,不允许使用其他符号
3.不允许使用系统关键字
将赋值与查询结合
set @userName = '刘德华';
set @userName:='刘青云';
select @userName as '读取到的userName变量值';
查询变量/使用变量·匿名的时候建议加上as
整数类型与浮点数类型测试
set @x=10,@y=3;
select @x / @y as '10/3的结果';
浮点数计算异常,显示无限000
set @dx=0.55,@dy=2;
select @dx + @dy;
去零操作,重新赋值即可以做到
set @result=(select @dx + @dy);
select @result;
通过修改变量的方式进行精准查询
set @cityName1='Kabul';
set @cityName2='Qandahar';
set @cityName3='Nijmegen';
select *from city where `Name`=@cityName;
select *from city where `Name` in(@cityName1,@cityName2,@cityName3);
select @cityName;