7dr3am7
7dr3am7

Reputation: 765

Mysql Select statement

I am querying a database as:

SELECT SUM(Hours) 
  from User 
 where surname = 'johnson';

Whenever I run it, as you know it will show selected Column with the name SUM(Hours).

Question:

Is there any way that I can "rename" it without altering the database table?

Upvotes: 0

Views: 94

Answers (2)

nickmoriarty
nickmoriarty

Reputation: 1263

SELECT SUM(Hours) as hours from User where surname='johnson';

Upvotes: 1

Bogdan Constantinescu
Bogdan Constantinescu

Reputation: 5356

You have to do something like this:

SELECT SUM(Hours) AS sumHours FROM User WHERE surname='johnson';

Now your column name is sumHours. You can name it whatever you want, but keep in mind to be descriptive.

Upvotes: 5

Related Questions