如何在 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)
廣告