MySQL Currency Icon Result

I want to create a currency icon (e.g. € or $) before the numbers returned from the request

SELECT COUNT(*) AS 'Aantal reizen', MIN(prijs) AS 'Laagste prijs', MAX(prijs AS 'Hoogste prijs', ROUND(AVG(prijs),0) AS 'Gemiddelde prijs' FROM reizen 

Is there a data type for this or is there a way?

+5
source share
2 answers

You can use CONCAT() for this

 SELECT COUNT(*) AS 'Aantal reizen', CONCAT('€ ', MIN(prijs)) AS 'Laagste prijs', CONCAT('€ ', MAX(prijs)) AS 'Hoogste prijs', CONCAT('€ ', ROUND(AVG(prijs), 0)) AS 'Gemiddelde prijs' FROM reizen 

From MySQL documentation on CONCAT ():

CONCAT (str1, str2, ..., STRN)

Returns the string that occurs when combining arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. The numeric argument is converted to the equivalent non-binary string form.

+3
source

You should use the CONCAT() function ( here , you will get a good explanation).

In your case, use:

 SELECT COUNT(*) AS 'Aantal reizen', CONCAT('€ ', MIN(prijs)) AS 'Laagste prijs', CONCAT('€ ', MAX(prijs)) AS 'Hoogste prijs', CONCAT('€ ', ROUND(AVG(prijs), 0)) AS 'Gemiddelde prijs' FROM reizen 
+2
source

Source: https://habr.com/ru/post/1243522/


All Articles