Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I'm developing a website where I want to display a graph of the average number per day of user input. There is an SQL query already present that returns this:

 

SELECT sum(number)/count(number) as average, date FROM stats WHERE * GROUP BY date

I got the result using the above query that I was looking for, but the result is in the form of three decimal precisions. How can I round this number? I can achieve it in PHP or my template engine, but is there any way to do this all in the database.

1 Answer

0 votes
by (11.7k points)

Try this out: 

SELECT 

  CAST(sum(number)/count(number) as UNSIGNED) as average, 

  date 

FROM stats 

WHERE * 

GROUP BY date

If you want to get more insights into SQL, check out this SQL Course from Intellipaat.

Browse Categories

...