You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL如何编写获取rate列20%值并生成新列的SELECT查询语法?

你可以直接在SELECT语句中对rate列做乘法计算,用AS关键字为计算结果指定列名即可,示例语句如下:

SELECT Fullname, position, rate, rate * 0.2 AS rate_20_percent
FROM 替换为你的实际表名;

补充说明:

  • 如果需要对计算结果保留指定小数位数,可以搭配ROUND()函数使用,比如保留2位小数的写法为ROUND(rate * 0.2, 2) AS rate_20_percent
  • 如果你希望新列输出为整数类型,可以用CAST(rate * 0.2 AS UNSIGNED) AS rate_20_percent实现类型转换

以你提供的测试数据为例,执行上述查询后得到的结果如下:

+-------------------+----------------------+------+------------------+
| Fullname          | position             | rate | rate_20_percent  |
+-------------------+----------------------+------+------------------+
| terry, sanchez    | Web Developer        | 1500 | 300              |
| bernie, nahoma    | Web Developer        | 1500 | 300              |
| marie, viray      | Web Developer        | 1500 | 300              |
| lucy, dante       | Web Developer        | 1500 | 300              |
| benedict, cruz    | Web Developer        | 1500 | 300              |
| jhon paul, arroyo | Web Designer         | 1200 | 240              |
| lewis, abante     | Web Designer         | 1200 | 240              |
| lito, lapid       | Database Administrat | 1350 | 270              |
| jerwin, aton      | Project Manager      | 2000 | 400              |
| benjie, cruz      | Dev Ops              | 1250 | 250              |
+-------------------+----------------------+------+------------------+

内容的提问来源于stack exchange,提问作者Jerwin Mathew Aton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 04:45:04