Is there way to output no decimal using mysql AVG() function [duplicate] - mysql

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

Related

Is there a way to specify the result type from math equation SQL [duplicate]

This question already has answers here:
CAST to DECIMAL in MySQL
(5 answers)
Closed 11 months ago.
Hello I was wondering if I could specify the return type of the result in a SQL query like this:
SELECT 100 - 10 AS result
I would like for it to be decimal so with complex operations:
SELECT 9023.43 - 8012.21 AS result DECIMAL(10,4)
Is it possible to do this with SQL?
Alternatively it can be parsed by PHP but I'd rather have it return as decimal(10,4) using sql
Based on this answer, you can cast a value as decimal. In your example, this would look like this:
SELECT CAST((9023.43 - 8012.21) AS DECIMAL(10,4)) AS result

How to calculate the number of days between two dates in sqlite or mysql? [duplicate]

This question already has answers here:
How to get the number of days of difference between two dates on MySQL?
(8 answers)
Closed 4 years ago.
How to calculate the number of days between two dates available in sqlite or mysql database table?
I have already searched it on google but couldn't found any solution.
What is proper query for getting number of days between two dates?
the query should look like this, MySQL:
SELECT datediff(current_date(), '2018-10-01') AS numberOfDays FROM dual;

3 month rolling/moving average [duplicate]

This question already has answers here:
Calculating a Moving Average MySQL?
(5 answers)
How do I calculate a moving average using MySQL?
(7 answers)
Closed 5 years ago.
Somehow this is not the initial request I have put forward. Indeed there are similar requests however as per my previous and initial message I tried the examples already delivered and some how I am failing to understand the concept.
What I want is a 3-month rolling average on the price.
The table title tbl consisting of the following productID, priceMonth, Price
The SQL statement I am using is the following:
SELECT AVG(Price) over(partition by productID between 2 preceding and current row)
as rolling_avg
FROM tbl
GROUP by priceMonth
order by price
I am not sure if the syntax is correct as it is giving me the following error:
An alias was previously found. (near "rolling_avg").
Therefore I cordially ask you the following:
1) I cannot locate where the alias problem is, can I cordially ask your assistance?
2) Is the above sql statements addresses what I am looking for? i.e a 3month rolling average?

Go Back To Beginning Of Month On Input Date MySQL [duplicate]

This question already has answers here:
How to get first day of every corresponding month in mysql?
(15 answers)
Closed 5 years ago.
Let's say that I have an input date of "2017-01-31" or "2017-02-28". I want to take this input date and make SQL change it to "2017-01-01" or "2017-02-01".
Is there a way to do this via MySQL functions in a query?
Several ways to do that. My preference is to use DATE_FORMAT to replace the day portion with constant 01.
SELECT DATE_FORMAT('2017-01-31','%Y-%m-01') + INTERVAL 0 DAY AS dt
There are lots of ways to skin that cat.
For example, we could subtract the integer number of days minus 1 ...
SELECT '2017-01-31' + INTERVAL 1-DAY('2017-01-31') DAY
(With the second form, the date value needs to be supplied twice. With the first, we only need to supply the value one time. I think the first form is easier for a future reader to understand... pretty clear what the author is intending.)
Use your date instead of my example:
SELECT CONCAT_WS('-',YEAR('2017-01-28'),MONTH('2017-01-28'),'01')

SQL add comma seperators on an integer value [duplicate]

This question already has an answer here:
MySQL - Thousands separator
(1 answer)
Closed 9 months ago.
I have a query:
select sum(invoiceamount) as invoice
from fact_salescount
where year in ({YEAR})
and month >= ({FROMMONTH})
and month <= ({TOMONTH})
This query can return a value from 100.00 to 15034115.93. It will return ONE value.
I would like to add, for each 000, like this: 15,034,115.93
I've seen a lot of similar questions, but none match mine. I hope someone can help me out.
I am using Pentaho and MySQL, and creating these queries within the Design Studio.
SELECT FORMAT(sum(invoiceamount),2)
FROM fact_salescount
WHERE year IN ({YEAR})
AND month >= ({FROMMONTH})
AND month <= ({TOMONTH})
This should do what you want, but I still don't like formatting number in the backend.