mysql - 如何在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
解决方案
您可以在同一查询中引用别名。尝试这个
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
推荐阅读
- elasticsearch - 如何为elasticsearch中的术语查询设置case_insensitive?
- graphql - 突变中的 GraphQL 嵌套节点 - 对象文字只能指定已知属性,并且类型中不存在“天”
- python - 用平均值替换特定列
- python - 总结python中字典列表的多个条件
- python - (python) 将对象创建为模块
- javascript - 如何在css和javascript中单击时使汉堡可见?
- node.js - 为什么我不能使用node js连接mongodb?
- python - 如何为 Python 数据类编写 Sphinx 文档?
- django - 自定义 Django All-auth 注册表单在注册后不发送确认电子邮件
- sqlite - 查询同一日期,不同年份 SQAlchemy