要将SELECT和SHOW命令结果合并为一个,请使用以下查询-
select @anyVariableName1 as anyAliasName1,@anyVariableName1 as anyAliasName2,......N;
要组合SELECT和SHOW,首先创建并初始化第一个变量。以下是查询-
mysql> set @first_name='John';
要组合SELECT和SHOW,请创建并初始化第二个变量。以下是查询-
mysql> set @last_name='Smith';
以下是结合SELECT和SHOW命令的查询-
mysql> select @first_name as EmployeeFirstName,@last_name as EmployeeLastName;
这将产生以下输出-
+-------------------+------------------+ | EmployeeFirstName | EmployeeLastName | +-------------------+------------------+ | John | Smith | +-------------------+------------------+ 1 row in set (0.00 sec)
为了合并系统全局变量,可以使用@@代替单个(@)。以下查询将合并当前的MySQL版本和端口号。
以下是查询-
mysql> select @@version as CURRENT_MYSQL_VERSION,@@port as CURRENT_MYSQL_PORT_NUMBER;
这将产生以下输出-
+-----------------------+---------------------------+ | CURRENT_MYSQL_VERSION | CURRENT_MYSQL_PORT_NUMBER | +-----------------------+---------------------------+ | 8.0.21 | 3306 | +-----------------------+---------------------------+ 1 row in set (0.00 sec)