Reputation: 5
So i have this query
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;
I want to round the multiplication done here
o.quantity * p.price AS total
but the ROUND() function will not take
ROUND(o.quantity * p.price AS total, 2)
and this didn't work either
o.quantity * p.price AS total, ROUND(total, 2)
how can I round the product ot o.quantity and p.price within the query?
Upvotes: 0
Views: 363
Reputation: 204
Try this
ROUND((o.quantity * p.price),2) AS total
I hope your problem will slove.
Upvotes: 0
Reputation: 3344
Try:
ROUND(orders.quantity * products.price, 2) AS total
You alias the column after you're done defining the entire column ... you can't alias a part of the column ..
Upvotes: 1