Title: sum MySQL column with spaces in name
Tags: mysql;sum
Question: How do I just simply sum a column in my MySQL database? I thought:
SELECT sum(Disbursement Amount) FROM payments
but this doesn't work. Says I have a syntax error near 'Amount)
I just need to know how to SUM ONE column of data and I can take it from there
I've searched for a couple days and have found nothing of use to me. I'm also brand spanking new to MySQL so I'm sure that's why ;)
Comment: a column name with a space inside is a bit  -  suboptimal. But quote it with backticks, `sum(\`Disbursement Amount\`)`. If the column is named `Disbursement` then shift the `Amount` behind the closing parenthesis: `sum(Disbursement) as Amount`

Comment: Yes I was thinking the same after the fact, this is just a test database I'm developing to start learning the little quirks of MySQL. Thanks for the suggestion

Here is the accepted answer: If you have a space in your column name (Disbursement Amount), then you need to use backticks to enclose the column name:
SELECT sum(`Disbursement Amount`)  as Total
FROM payments;
My suggestion would be to not use spaces in your tables and column names.  If you want to have a separator between the two words, you can use an underscore:
SELECT sum(Disbursement_Amount)  as Total
FROM payments;
Comment for this answer: @bluefeet His column is `VARCHAR` and the values have commas: `2,775` ... So `2+2+2+606 = 612`
Comment for this answer: Thank you for the quick response, I appreciate it. My query runs now with your suggestion, however, the SUM amount is completely wrong. I'm getting a sum of 612 but 2,775 + 2,775 + 2,775 + 606 is not 612. Any ideas?
Comment for this answer: I apologize bluefeet, but I'm extremely new to MySQL and am not sure how to export those yet. The above are the only values in my column though
Comment for this answer: ypercube is correct, it appears to only be summing the first digits. I removed the commas and all is good. THANK YOU SO MUCH EVERYONE!!!
Comment for this answer: Can you post your table structure and sample data?
Comment for this answer: @EricJ If you run `select Disbursement Amount from payments` what do you get as a result?  You only get 4 rows?   Are you running this exact query?
Comment for this answer: @EricJ You should be storing numbers as an numeric datatype. Don't store them as a string.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:06/19/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<mysql><sum>', 'Title': 'sum MySQL column with spaces in name', 'ViewCount': 2798, 'id': 17200987, 'user_AboutMe': '', 'user_AccountId': 2639920.0, 'user_DisplayName': 'TypeM1smatch', 'user_Reputation': 225.0, 'user_Views': 28.0, 'user_id': 2283799.0}}