Hello, I have writed a custom query in a dynamic list.I want to round up UnitPrice.As I hear,I must use CAST keyword.How can I do this?
The question is in 5.Module 4.Task.
SELECT SalesProducts.Product AS Product, SUM(SalesProducts.Quantity) AS Quantity, AVG(SalesProducts.UnitPrice) AS UnitPrice, SUM(SalesProducts.LineTotal) AS LineTotal FR OM Document.Sales.Products AS SalesProducts WHERE SalesProducts.LineTotal > ¶meter
SELECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,
AVG(CAST(SalesProducts.UnitPrice AS NUMBER(15, 2))) AS UnitPrice,
SUM(SalesProducts.LineTotal) AS LineTotal
FR OM
Document.Sales.Products AS SalesProducts
WHERE
SalesProducts.LineTotal > ¶meter
GROUP BY
SalesProducts.Product
ORDER BY
LineTotal ASC
SEL ECT SalesProducts.Product AS Product, SUM(SalesProducts.Quantity) AS Quantity, AVG(CAST(SalesProducts.UnitPrice as number(15,2))) AS UnitPrice, SUM(SalesProducts.LineTotal) AS LineTotal FR OM Document.Sales.Products AS SalesProducts WHERE SalesProducts.LineTotal > ¶meter
in your case, the request text will be as follows:
Code
SELECT
SalesProducts.Product AS Product,
SUM(SalesProducts.Quantity) AS Quantity,
CAST(AVG(SalesProducts.UnitPrice) as number(12,2)) AS UnitPrice,
SUM(SalesProducts.LineTotal) AS LineTotal
FROM
Document.Sales.Products AS SalesProducts
GROUP BY
SalesProducts.Product
ORDER BY
LineTotal ASC
that is, we first get the average, and then round it up.