Chris Benzola
Chris Benzola

Reputation: 17

How do you remove leading 0 before decimal in mySQL

I know this is probably a simple fix and there's many posts on here, but after looking through many of them I can't get it to work.

I am running a mySQL query to return batting average for a baseball player:

SELECT playerID, ROUND(H/AB,3) AS 'AVG'
FROM Batting
WHERE playerID = 'troutmi01'

When I run that it returns

troutmi01   0.220
troutmi01   0.326
troutmi01   0.323

However, I would like it to return

troutmi01   .220
troutmi01   .326
troutmi01   .323

Upvotes: 0

Views: 100

Answers (1)

forpas
forpas

Reputation: 164099

You can use TRIM() function:

SELECT playerID, TRIM(LEADING '0' FROM ROUND(H/AB,3)) AS 'AVG'
FROM Batting
WHERE playerID = 'troutmi01'

Upvotes: 1

Related Questions