语法:SELECT 字段名1, 字段名2, ...... , 字段名n FROM 表名 WHERE 查询条件 BETWEEN ... AND ... ;
mysql> SELECT f_name, f_price FROM fruits WHERE f_price BETWEEN 2.00 AND 10.20 ; +------------+---------+ | f_name | f_price | # 查询价格在2.00到10.20元之间的水果名称和价格 +------------+---------+ | apple | 5.20 | | apricot | 2.20 | | blackberry | 10.20 | | berry | 7.60 | | xxxx | 3.60 | | melon | 8.20 | | cherry | 3.20 | | lemon | 6.40 | | xbabay | 2.60 | | coconut | 9.20 | | grape | 5.30 | | xbababa | 3.60 | +------------+---------+
mysql> SELECT f_name, f_price FROM fruits WHERE f_price NOT BETWEEN 2.00 AND 10.20 ; +--------+---------+ | f_name | f_price | # 查询价格不在2.00到10.20元之间的水果名称和价格 +--------+---------+ | orange | 11.20 | | mango | 15.70 | | xxtt | 11.60 | | banana | 10.30 | +--------+---------+
时间: 2024-10-10 02:15:29