Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

PostgreSQL BETWEEN 运算符


BETWEEN

The BETWEEN 运算符选择给定范围内的值。这些值可以是数字、文本或日期。

The BETWEEN 运算符是包含性的:开始值和结束值都包含在内。

示例

选择价格在 10 到 15 之间的所有产品

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 15;
运行示例 »

BETWEEN 文本值

The BETWEEN 运算符也可以用于文本值。

结果返回所有按字母顺序在指定值之间的记录。

示例

选择所有介于 'Pavlova' 和 'Tofu' 之间的产品

SELECT * FROM Products
WHERE product_name BETWEEN 'Pavlova' AND 'Tofu';
运行示例 »

如果我们在上面的示例中添加一个 ORDER BY 子句,它会更容易阅读

示例

与上面相同的示例,但我们按 product_name 对其进行排序

SELECT * FROM Products
WHERE product_name BETWEEN 'Pavlova' AND 'Tofu'
ORDER BY product_name;
运行示例 »

BETWEEN 日期值

The BETWEEN 运算符也可以用于日期值。

示例

选择 2023 年 4 月 12 日到 2023 年 5 月 5 日之间的所有订单

SELECT * FROM orders
WHERE order_date BETWEEN '2023-04-12' AND '2023-05-05';
运行示例 »

PostgreSQL 练习

通过练习测试自己

练习

选择所有 year 字段值介于 1970 年和 1980 年之间的汽车

SELECT * FROM cars
WHERE year ;
        

开始练习


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.