在MySQL中使用别名(alias)可以通过AS关键字或空格来实现。以下是几种常用的情况:
SELECT column_name AS alias_name
FROM table_name;
SELECT t1.column_name
FROM table_name AS t1;
SELECT t1.column_name, t2.column_name
FROM table_name AS t1
JOIN table_name AS t2 ON t1.id = t2.id;
SELECT alias_name
FROM (SELECT column_name AS alias_name
FROM table_name) AS subquery_alias;
在使用别名时,可以让查询结果更易读,提高代码的可读性和可维护性。