1

I'm a MySQL scrub, and I have asked around and checked around the internet for what I'm sure will turn out to be something obvious, but I'm very frustrated with what I thought would be a very, very simple query not working. So here goes. Please be gentle.

Basically, in a large database, some of the column names contain mathematical operators like "/" and "+." (Don't ask, it's not my database, I can't do anything about it). Here is the "essence" of my query (I took out the irrelevant stuff for the sake of this question):

  SELECT PlayerId, 
         Season,
         WPA/LI AS WPALI
    FROM tht.stats_batting_master 
   WHERE Season = "2010" 
     AND teamid > 0 
     AND PA >= 502
GROUP BY playerid
ORDER BY WPALI DESC

When I run this, it returns "Unknown column 'LI' in 'field list'," I assume because it sees the "/" in WPA/LI as a division sign. Like I said, I'm sure this is easy enough to work around (it must be given how much this database is used), but I haven't' been able to figure out how.

Thanks in advance for any help.

1
  • Thanks, both of you... I knew it would be some elementary piece of MySQL knowledge that my "learn on a need basis" knowledge set would have excluded. It worked. Commented Jan 12, 2011 at 13:45

2 Answers 2

5

Use backticks to escape such situations:

  SELECT PlayerId, 
         Season,
         `WPA/LI` AS WPALI
    FROM tht.stats_batting_master 
   WHERE Season = "2010" 
     AND teamid > 0 
     AND PA >= 502
GROUP BY playerid
ORDER BY WPALI DESC
Sign up to request clarification or add additional context in comments.

Comments

0

Did you try this syndax:

SELECT PlayerId, Season `WPA/LI` AS WPALI
FROM tht.stats_batting_master
WHERE Season="2010" AND teamid>0 AND PA>=502
GROUP BY playerid
ORDER BY WPALI DESC

1 Comment

Thanks, I figured it out, I knew it would be something I should have known but didn't with my hodgepodge knowledge of MySQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.