如何删除 MySQL 中特定值范围以上的值?
让我们首先创建一个表 −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PlayerName varchar(100), PlayerScore int ); Query OK, 0 rows affected (0.97 sec)
通过使用插入命令在表中插入一些记录 −
mysql> insert into DemoTable(PlayerName,PlayerScore) values('Chris',780); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Sam',1100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Mike',900); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Bob',890); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Carol',1000); Query OK, 1 row affected (0.20 sec)
使用选择语句从表中显示所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+----+------------+-------------+ | Id | PlayerName | PlayerScore | +----+------------+-------------+ | 1 | Chris | 780 | | 2 | Sam | 1100 | | 3 | Mike | 900 | | 4 | Bob | 890 | | 5 | Carol | 1000 | +----+------------+-------------+ 5 rows in set (0.00 sec)
以下是 MySQL 中删除特定值范围以上的值的查询 −
mysql> delete from DemoTable where PlayerScore > 900; Query OK, 2 rows affected (0.18 sec)
让我们再次检查表记录。
mysql> select *from DemoTable;
这将产生以下输出 −
+----+------------+-------------+ | Id | PlayerName | PlayerScore | +----+------------+-------------+ | 1 | Chris | 780 | | 3 | Mike | 900 | | 4 | Bob | 890 | +----+------------+-------------+ 3 rows in set (0.00 sec)
广告