选择以特定字母开头的特定类型的列并连接名称
对于以某个字母开头的特定类型的列,请使用LIKE。要连接列名称,请使用GROUP_CONCAT(),如以下语法所示:
SELECT group_concat(COLUMN_NAME separator ' , ')FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = "yourTableName"
AND table_schema = "yourDatabaseName"
AND column_name LIKE "yourSpecificLetter%";
让我们首先创建一个表-
mysql> create table DemoTable671(ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
ClientName varchar(100),
ClientAge int,
ClientAddress varchar(200),
ClientCountryName varchar(100)
);
以下是查询以特定字母开头的特定类型的列并获取所有列名称以进行串联的查询-
mysql> SELECT group_concat(COLUMN_NAME separator ' , ')FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = "DemoTable671"
AND table_schema = "web"
AND column_name LIKE "Cl%";
这将产生以下输出-
+-----------------------------------------------------------------------+| group_concat(COLUMN_NAME separator ' , ') |
+-----------------------------------------------------------------------+
| ClientId , ClientName , ClientAge , ClientAddress , ClientCountryName |
+-----------------------------------------------------------------------+
1 row in set (0.00 sec)
以上是 选择以特定字母开头的特定类型的列并连接名称 的全部内容, 来源链接: utcz.com/z/347294.html