如何顯示 MySQL 中某個表中的列名稱(排除某些列)?


要排除某些列名稱,請使用 NOT IN。

我們首先建立一個表 -

mysql> create table DemoTable780 (
   CustomerId int,
   CustomerName varchar(100),
   CustomerAge int,
   CustomerCountryName varchar(100),
   isMarried tinyint(1)
);
Query OK, 0 rows affected (0.47 sec)

以下是如何排除結果的查詢 -

mysql> select group_concat(column_name) from `information_schema`.`COLUMNS` m
   where
   table_schema = 'web' and
   table_name = 'DemoTable780' and
   column_name not in ('CustomerId','CustomerCountryName')
   group by table_schema,table_name;

這將產生以下輸出 -

+------------------------------------+
| group_concat(column_name)          |
+------------------------------------+
| CustomerName,CustomerAge,isMarried |
+------------------------------------+
1 row in set (0.01 sec)

更新於:09-Sep-2019

332 次瀏覽

開啟你的 職業生涯

完成課程獲取認證

入門
廣告
© . All rights reserved.