#聲明變量
#1.標識符不能以數字開頭
#2.只能使用_或$符號,不能使用其他符號
#3.不能使用系統關鍵字
set@userName='劉德華';
select @userName:='劉青云';#將賦值與查詢結合
#查詢變量、使用變量,匿名的時候建議加上as
select @userName as '讀取到的userName變量值';
#整數類型與浮點數類型測試
set @x=5,@y=7;
select @x+@y as '5+7的結果';
set @dx=0.5,@dy=2;
select @dx+@dy;#浮點數計算異常顯示無限000
#去零操作 重新賦值既可以做到
set @result=(select @dx+@dy);
select @result;
#通過修改變量的方式進行精準查詢
set @cityName1='Kabul';
set @cityName2='Qandahar';
set @cityName3='Maastricht';
select * from city where`Name`=@cityName1;select * from city where `Name` in (@cityName1,@cityName2,@cityName3);
select @cityName;