I want to create a currency icon (like € or $) in front of the numbers that are returned from the query
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 around?
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.
You should use the CONCAT()
function (here you 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With