|
@@ -179,4 +179,40 @@ select * from (values
|
|
|
('The Dark Knight', 9.1, 2008),
|
|
|
('Inception', 8.8, 2010)
|
|
|
) t(movie, imdb_rating, year);
|
|
|
+```
|
|
|
+
|
|
|
+Фильтрация данных
|
|
|
+
|
|
|
+```sql
|
|
|
+---Ключевое слово `WHERE` означает фильтрацию, то есть достань мне все записи из таблички авторов, где поле `author_id = 1`
|
|
|
+select * from author where author_id=1;
|
|
|
+
|
|
|
+-- and, or, not
|
|
|
+select * from author where name='Михаил Шолохов' and author_id=200;
|
|
|
+select * from author where name='Михаил Шолохов' or false;
|
|
|
+select * from author where not author_id = 1;
|
|
|
+select * from author where author_id != 1;
|
|
|
+select * from author where author_id <> 1;
|
|
|
+
|
|
|
+-- between
|
|
|
+select * from author where author_id between 1 and 2;
|
|
|
+select * from author where author_id >= 1 and author_id <= 2;
|
|
|
+
|
|
|
+-- IN
|
|
|
+select * from author where author_id in (1, 2, 3, 4, 5);
|
|
|
+-- Это можно сделать с подзапросом
|
|
|
+select * from author where author_id in (
|
|
|
+ select author_id from book
|
|
|
+);
|
|
|
+
|
|
|
+-- LIKE (передача шаблона)
|
|
|
+select * from author where name like '%Шолохов%';
|
|
|
+
|
|
|
+select * from family where family_name like '%а%' or family_name like '%с%';
|
|
|
+
|
|
|
+-- ilike - шаблон без учета регистра
|
|
|
+select * from author where name like '%шолохов%';
|
|
|
+
|
|
|
+-- reg exp
|
|
|
+select name from book where name ~ '^\w+\W+\w+$';
|
|
|
```
|