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 WHERE - 过滤数据


过滤记录

WHERE 子句用于过滤记录。

它用于仅提取满足指定条件的那些记录。

如果我们只想返回 cityLondon 的记录,我们可以在 WHERE 子句中指定。

示例

SELECT * FROM customers
WHERE city = 'London';
运行示例 »

文本字段与数字字段

PostgreSQL 要求文本值用引号括起来。

但是,数字字段不应包含在引号中

示例

SELECT * FROM customers
WHERE customer_id = 19;
运行示例 »

数字字段周围的引号不会导致错误,但最好始终不使用引号编写数字值。


大于

使用 > 运算符返回 customer_id 大于 80 的所有记录

示例

SELECT * FROM customers
WHERE customer_id > 80;
运行示例 »

数字字段周围的引号不会导致错误,但最好始终不使用引号编写数字值。


PostgreSQL 练习

通过练习测试自己

练习

编写正确的 SQL 语句以从 customers 表中选择所有 city 值为 "Berlin" 的记录。

SELECT * FROM customers
;
        

开始练习


×

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.