如何在 MySQL 中顯示一些列(而非全部)?
若要顯示部分列,請使用 NOT IN 並設定不想顯示的那些列。我們首先建立一個表。以下是查詢 −
mysql> create table student_Information -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(50), -> StudentAge int, -> StudentAddress varchar(100), -> StudentAllSubjectScore int -> ); Query OK, 0 rows affected (0.69 sec)
以下是顯示上述表描述的查詢 −
mysql> desc student_Information;
這將生成以下輸出 −
+------------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(50) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentAddress | varchar(100) | YES | | NULL | | | StudentAllSubjectScore | int(11) | YES | | NULL | | +------------------------+--------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
以下是僅顯示部分列的查詢 −
mysql> SHOW COLUMNS FROM student_Information where field not in('StudentAddress','StudentAllSubjectScore');
這將生成以下輸出 −
+-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(50) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
廣告