1

In MySQL, how do I change the column name of a table from "sum(xyz)", to say "xyz"? I have tried the following solutions for just changing the column name:

Change Column Name in MySQL

Rename column SQL Server 2008

However, it always throws up an error saying that the syntax is not right. I feel that it is because of the sum() function, because it doesn't allow me to use SELECT on that column too (when done separately). Is there any way past this? A solution to access the values in that column without changing the column header is also appreciated!

I am using WAMPSERVER to run MySQL version 5.1.53.

Thanks

3 Answers3

1

Try this:

ALTER TABLE mytable CHANGE COLUMN `sum(xyz)` `xyz` <yourdatatype>;
Halko Karr-Sajtarevic
  • 2,248
  • 1
  • 16
  • 14
1

So, your column name is "sum(xyz)" and you can't do a select because of the "sum()" function.

Try

SELECT ` sum(xyz)` as xyz from mytable;

Krishnakumar
  • 725
  • 1
  • 6
  • 11
0

Use AS to make virtual field

Your code will be same as SELECT SUM(yourField) as xyz FROM table

Riajul Islam
  • 1,425
  • 15
  • 19