计算机网络/计算机科学与应用/系统/运维/开发

MySQL8 查询结果 别名


as给列起别名,也可以省略as 

mysql> SELECT 
    -> DATE_FORMAT(t,'%M %e,%Y') AS date_sent,
    -> CONCAT(srcuser,'@',srchost) AS sender,
    -> size
    -> FROM mail;
+-------------+---------------+---------+
| date_sent   | sender        | size    |
+-------------+---------------+---------+
| May 11,2014 | barb@saturn   |   58274 |
| May 12,2014 | tricia@mars   |  194925 |
| May 12,2014 | phil@mars     |    1048 |
| May 12,2014 | barb@saturn   |     271 |
| May 14,2014 | gene@venus    |    2291 |
| May 14,2014 | phil@mars     |    5781 |
| May 14,2014 | barb@venus    |   98151 |
| May 14,2014 | tricia@saturn | 2394482 |
| May 15,2014 | gene@mars     |    3824 |
| May 15,2014 | phil@venus    |     978 |
| May 15,2014 | gene@mars     |  998532 |
| May 15,2014 | gene@saturn   |    3856 |
| May 16,2014 | gene@venus    |     613 |
| May 16,2014 | phil@venus    |   10294 |
| May 19,2014 | phil@mars     |     873 |
| May 19,2014 | gene@saturn   |   23992 |
+-------------+---------------+---------+
16 rows in set (0.00 sec)


如果MySQL报告某个别名错误,那么检查下是否使用了保留字,要么更换别名要么在别名上加引号

mysql> SELECT 1 AS 'INTEGER';



别名 mysql sql

日子过着过着就有了答案,努力走着走着就有了温柔的着落。

评论

^