Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currency icon result MySQL

Tags:

mysql

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?

like image 694
Max Avatar asked Feb 21 '16 17:02

Max


Video Answer


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'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.

like image 160
baao Avatar answered Oct 22 '22 07:10

baao


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
like image 43
SevenOfNine Avatar answered Oct 22 '22 07:10

SevenOfNine