Mysql – Giving a name to a dynamic column

MySQL

I have written a query to fetch a time internal:

select *, (Time + interval '2012-12-18 13:36:47' minute)  from chatnotiservice;

Is it possible to name the (Time + interval '2012-12-18 13:36:47' minute) column?

Best Answer

Use AS. For example:

mysql> select 'data' as mycolumnname;
+--------------+
| mycolumnname |
+--------------+
| data         |
+--------------+
1 row in set (0.00 sec)

mysql> 

If you actually want to name the column after the date operation you're performing (your question isn't clear), you can do it by enclosing it in backticks. For example:

mysql> select 'data' as `Time + interval '2012-12-18 13:36:47' minute` ;
+----------------------------------------------+
| Time + interval '2012-12-18 13:36:47' minute |
+----------------------------------------------+
| data                                         |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql>

I suspect what you mean is the following:

select *,(Time + interval '2012-12-18 13:36:47' minute) AS mytime from chatnotiservice;
Related Question