如何在 MySQL 中將 ID 列選擇為 null?
我們首先建立一個表。建立表的查詢如下
mysql> create table selectAllDemo - > ( - > Name varchar(100), - > Age int - > ); Query OK, 0 rows affected (1.90 sec)
使用 insert 命令在表中插入一些記錄。
查詢如下
mysql> insert into selectAllDemo values('John',25);
Query OK, 1 row affected (0.99 sec)
mysql> insert into selectAllDemo values('Carol',26);
Query OK, 1 row affected (0.42 sec)
mysql> insert into selectAllDemo values('Bob',30);
Query OK, 1 row affected (1.57 sec)
mysql> insert into selectAllDemo values('Sam',35);
Query OK, 1 row affected (0.26 sec)使用 select 語句從表中顯示所有記錄。
查詢如下
mysql> select *from selectAllDemo;
輸出如下
+-------+------+ | Name | Age | +-------+------+ | John | 25 | | Carol | 26 | | Bob | 30 | | Sam | 35 | +-------+------+ 4 rows in set (0.16 sec)
以下是在選擇僅為 NULL 的 ID 列的查詢
mysql> select NULL AS Id,tbl.Name,tbl.Age from selectAllDemo tbl where Age=35;
輸出如下
+------+------+------+ | Id | Name | Age | +------+------+------+ | NULL | Sam | 35 | +------+------+------+ 1 row in set (0.07 sec)
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式語言
C++
C#
MongoDB
MySQL
JavaScript
PHP