时间:2021-07-01 10:21:17 帮助过:18人阅读
SELECT * FROM Websites WHERE alexa BETWEEN 1 AND 20;
如需显示不在上面实例范围内的网站,请使用 NOT BETWEEN:
SELECT * FROM Websites WHERE alexa NOT BETWEEN 1 AND 20;
下面的 SQL 语句选取alexa介于 1 和 20 之间但 country 不为 USA 和 IND 的所有网站:
SELECT * FROM Websites WHERE (alexa BETWEEN 1 AND 20) AND NOT country IN (‘USA‘, ‘IND‘);
下面的 SQL 语句选取 name 以介于 ‘A‘ 和 ‘H‘ 之间字母开始的所有网站:
SELECT * FROM Websites WHERE name BETWEEN ‘A‘ AND ‘H‘;
下面的 SQL 语句选取 name 不介于 ‘A‘ 和 ‘H‘ 之间字母开始的所有网站:
SELECT * FROM Websites WHERE name NOT BETWEEN ‘A‘ AND ‘H‘;
下面是 "access_log" 网站访问记录表的数据,其中:
mysql> SELECT * FROM access_log; +-----+---------+-------+------------+ | aid | site_id | count | date | +-----+---------+-------+------------+ | 1 | 1 | 45 | 2016-05-10 | | 2 | 3 | 100 | 2016-05-13 | | 3 | 1 | 230 | 2016-05-14 | | 4 | 2 | 10 | 2016-05-14 | | 5 | 5 | 205 | 2016-05-14 | | 6 | 4 | 13 | 2016-05-15 | | 7 | 3 | 220 | 2016-05-15 | | 8 | 5 | 545 | 2016-05-16 | | 9 | 3 | 201 | 2016-05-17 | +-----+---------+-------+------------+ 9 rows in set (0.00 sec)
下面的 SQL 语句选取 date 介于 ‘2016-05-10‘ 和 ‘2016-05-14‘ 之间的所有访问记录:
SELECT * FROM access_log WHERE date BETWEEN ‘2016-05-10‘ AND ‘2016-05-14‘;
[13]SQL BETWEEN 操作符
标签:rom 次数 sites oba www access strong print sql