-1

How do you use MAX and ROUND at the same time?

i.e.

SELECT customer_id, MAX(some_number) FROM customer_data GROUP BY customer_id;

60.2354125

Would like to return the result of 60.24

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

2 Answers2

2

You would write this as:

SELECT customer_id, ROUND(MAX(some_number), 2)
FROM customer_data
GROUP BY customer_id;

EDIT:

Based on your comment, you can convert to a numeric first:

SELECT customer_id, ROUND(MAX(some_number)::numeric, 2)
FROM customer_data
GROUP BY customer_id;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • I think I'm not able to get this to work because of the data type? I get the following error message: ERROR: function round(double precision, integer) does not exist – user16362381 Aug 22 '21 at 23:34
0

Thanks for pointing me in the right direction @Gordon. The solution was casting as numeric

round(MAX(cast(some_number as numeric)),2)