gpt4 book ai didi

mysql - 如何在sql查询中四舍五入两列的乘积

转载 作者:行者123 更新时间:2023-11-29 11:37:45 24 4
gpt4 key购买 nike

所以我有这个查询

SELECT p.id product_id
, o.id order_id
, u.id user_id
, o.quantity
, o.created_at
, o.total
, o.quantity * p.price total
, o.created_at
, p.price
, p.name
, u.username
FROM products p
LEFT
JOIN orders o
ON o.product_id = p.id
LEFT
JOIN users u
ON u.id = o.user_id;

我想对这里完成的乘法进行四舍五入

o.quantity * p.price AS total

但 ROUND() 函数不会采用

ROUND(o.quantity * p.price AS total, 2)

这也不起作用

o.quantity * p.price AS total, ROUND(total, 2)

如何在查询中对产品 ot o.quantity 和 p.price 进行四舍五入?

最佳答案

尝试:

ROUND(orders.quantity * products.price, 2)  AS total

完成整个列的定义后,您可以为该列添加别名...您不能为该列的一部分添加别名..

关于mysql - 如何在sql查询中四舍五入两列的乘积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36315608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com