This question already has answers here:
Format number to 2 decimal places
(6 answers)
Closed 7 years ago.
I have the following query:
SELECT
SUM(`SPEND_AMOUNT`) AS 'Total Spend Amount',
SUM(`SPEND_AMOUNT`) / COUNT(DISTINCT `INVOICENUMBER`) AS 'Average Spend Amount'
FROM
`TABLE`
I would like to truncate(?) the results for "Average Spend Amount" to two decimal places.Thanks for the help.
Round(SUM(SPEND_AMOUNT) / COUNT(DISTINCT INVOICENUMBER), 2)
Related
This question already has answers here:
How can I make the decimal places of AVG function in sql limit to 2 only?
(3 answers)
Closed 6 days ago.
SELECT AVG(
TIMESTAMPDIFF(MINUTE,
customer_service_ticket_raise_time,
CURRENT_TIMESTAMP()
)
) AS avg_waiting_time
FROM customer_service_ticket;
I am writing this SQL query to display the average waiting time customers have been waiting but it outputs as a decimal value e.g. 29.8333. Is there any way I want get rid of the decimals and display the minutes as a whole value.
you can wrap your value with the CEILING function
https://www.w3schools.com/sql/func_sqlserver_ceiling.asp
This question already has answers here:
Select only year from MySql
(3 answers)
Closed 4 years ago.
I'm trying to leverage 'date_trunc' function in a query and it returns the below error
FUNCTION database.date_trunc does not exist.
Please advice
You could use DATE_FORMAT(created_at ,'%Y-01-01') to get first day of year:
SELECT DATE_FORMAT(created_at ,'%Y-01-01') AS `year`, COUNT(*) AS cnt
FROM sales_order
GROUP BY DATE_FORMAT(created_at ,'%Y-01-01')
ORDER BY `year`;
DATE_TRUNC is supported by PostgreSQL.
This question already has answers here:
Calculate a running total in MySQL
(5 answers)
Closed 4 years ago.
How can i do cumulative sum?
My query is :
select dateb,ricetype,bajet1
from bajet
where ricetype='grand total'
How do i archieve 'New Value'?
You can do it like below :
set #CumSum := 0;
select dateb, ricetype, bajet1, (#CumSum := #CumSum + bajet1) as New_Value
from bajet where ricetype='grand total';
This question already has answers here:
Format number to 2 decimal places
(6 answers)
Closed 8 years ago.
I need to change my query to return only 2 decimal points
SELECT (AVG(cost)) AS 'Average Cost $'
FROM donuts
WHERE cost;
I don't want to use the ROUND function because I wont get a decimal.
SELECT ROUND(AVG(cost)) AS 'Average Cost $'
FROM donuts
WHERE cost;
Any Suggestions,
You will get decimal point with the mysql round() function. You have to pass number of decimal points you wish to display. Default value is 0.
For example, in order to get 2 decimal points you will run this query:
SELECT ROUND(AVG(cost), 2) AS 'Average Cost $'
FROM donuts
WHERE cost > 0;
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_round
This question already has answers here:
What is the difference between UNION and UNION ALL?
(19 answers)
Closed 9 years ago.
Can anyone please tell me the difference where to use union and where to use uinon all in mysql
UNION gets distinct values, UNION ALL doesn't.