首页 > 解决方案 > 如何在mysql中使用数学

问题描述

我正在创建数据库视图,但如何计算 ant 将该列像图片一样。

在此处输入图像描述

编辑:

SELECT 
   orders.id AS order_id, 
   order_products.qty AS p_count, 
   order_products.unit_price AS p_price, 
   order_products.pp_calculated, 
   orders.customer_id, 
   products.point_percentage AS point_percentage 
FROM orders 
INNER JOIN order_products ON orders.id = order_products.order_id 
INNER JOIN products ON order_products.product_id = products.id

标签: mysqlsql

解决方案


您可以在同一查询中引用别名。尝试这个

SELECT 
   orders.id AS order_id, 
   order_products.qty AS p_count, 
   order_products.unit_price AS p_price, 
  ((order_products.qty*order_products.unit_price*100)/products.point_percentage)pp_calculated
   orders.customer_id, 
   products.point_percentage AS point_percentage 
FROM orders 
INNER JOIN order_products ON orders.id = order_products.order_id 
INNER JOIN products ON order_products.product_id = products.id

推荐阅读