如何在 MySQL 查询中编写不超过?
查询中的不超过可以用小于或等于 ( <= ) 来简单编写。语法如下 −
select * from yourTableName where yourColumnName<=yourColumnName;
我们首先创建一个表 −
mysql> create table DemoTable1480 -> ( -> StudentName varchar(40), -> StudentMarks int -> ); Query OK, 0 rows affected (0.50 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1480 values('Chris',78); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1480 values('Bob',45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1480 values('John',67); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1480 values('Adam',56); Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1480;
这将产生以下输出 −
+-------------+--------------+ | StudentName | StudentMarks | +-------------+--------------+ | Chris | 78 | | Bob | 45 | | John | 67 | | Adam | 56 | +-------------+--------------+ 4 rows in set (0.00 sec)
以下是在 MySQL 查询中编写不超过符号的查询 −
mysql> select * from DemoTable1480 where StudentMarks <=65;
这将产生以下输出 −
+-------------+--------------+ | StudentName | StudentMarks | +-------------+--------------+ | Bob | 45 | | Adam | 56 | +-------------+--------------+ 2 rows in set (0.00 sec)
广告