-- 示例代码:在 MySQL 中进行加法运算
-- 假设我们有一个名为 `orders` 的表,其中包含订单信息
-- 表结构如下:
-- orders (id INT, product_name VARCHAR(100), quantity INT, price DECIMAL(10, 2))
-- 现在我们想要计算每个订单的总价(数量 * 单价),并加上一个固定的运费 10.00
SELECT
id,
product_name,
quantity,
price,
(quantity * price) + 10.00 AS total_price_with_shipping
FROM
orders;
-- 解释:
-- 1. `quantity * price` 计算每个订单的商品总价。
-- 2. `+ 10.00` 添加固定的运费。
-- 3. `AS total_price_with_shipping` 将计算结果命名为 `total_price_with_shipping`。
上一篇:mysql 自增函数
下一篇:mysql排名函数rank怎么用
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站