mysql> select * from Tender;
+----+---------------+--------------+
| Sr | CompanyName | Tender_value |
+----+---------------+--------------+
| 1 | Abc Corp. | 250.369003 |
| 2 | Khaitan Corp. | 265.588989 |
| 3 | Singla group. | 220.255997 |
| 4 | Hero group. | 221.253006 |
| 5 | Honda group | 225.292266 |
+----+---------------+--------------+
5 rows in set (0.04 sec)
现在,在下面的查询中,我们将ender_value的最大值(四舍五入到小数点后两位)设置为变量@Val_Max。
mysql> SET @Val_Max = (SELECT ROUND(MAX(tender_value),2) from tender);
Query OK, 0 rows affected (0.00 sec)
mysql> Select @Val_Max;
+----------+
| @Val_Max |
+----------+
| 265.59 |
+----------+
1 row in set (0.00 sec)
登录后复制
以上就是如何使用 SET 语句将 SELECT 结果分配给 MySQL 用户变量?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!