Max A Max A - 2 months ago 19
MySQL Question

Currency icon in MySQL database

I want to create a currency icon (like € or $) in front of the numbers that are returned from the quer

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

Answer

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's documentation on CONCAT():

CONCAT(str1,str2,...,strN)

Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent nonbinary string form.

Comments