全部语句
#MySQL变量的声明与使用
# 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.1,@dy=0.4;
select @dx + @dy;#浮点数计算显示异常无限0
#去零操作 重新赋值既可以做到
set @result=(select @dx + @dy);
select @result;
#通过修改变量的方式进行精准查询
set @cityName1='Kabul';
set @cityName2='Herat';
set @cityName3='Maastricht';
select * from city where `Name`=@cityName1;
select * from city where `Name` in(@cityName1,@cityName2,@cityName3);
select @cityName;
赋值与查询结合
MySQL变量的声明与使用
1、标识符不能以数字作为开头
2、只能使用_或$符号,不允许使用其他符号。
3、不允许使用系统关键字
set @userName ='刘德华';
SELECT @userName:='刘青云';#将赋值与查询结合
# 查询变量/使用变量·匿名的时候建议加上as
SELECT @userName as '读取到的userName变量值';
整数类型与浮点数类型测试
浮点数计算显示异常无限0
set @x=5,@y=7;
SELECT @x + @y as '5+7的结果';
去零操作 重新赋值既可以做到
set @dx=0.2,@dy=0.3;
set @result=(select @dx + @dy);
select @result;
通过修改变量的方式进行精准查询
在world里的city表中进行的查询(可以查询一个或多个)
set @cityName1='Kabul';
set @cityName2='Herat';
set @cityName3='Maastricht';
select * from city where `Name`=@cityName1;#一个
select * from city where `Name` in(@cityName1,@cityName2,@cityName3);#多个
select @cityName1;