dm 2 месяцев назад
Родитель
Сommit
6150cacec1

+ 12 - 0
.obsidian/workspace.json

@@ -20,6 +20,18 @@
               "icon": "lucide-file",
               "title": "Создание таблиц"
             }
+          },
+          {
+            "id": "0220e278e9e56f6c",
+            "type": "leaf",
+            "state": {
+              "type": "release-notes",
+              "state": {
+                "currentVersion": "1.8.4"
+              },
+              "icon": "lucide-book-up",
+              "title": "Release Notes 1.8.4"
+            }
           }
         ]
       }

+ 9 - 1
docs/Script-1.sql

@@ -36,4 +36,12 @@ select genus_name, genus_id from genus;
 select genus_name as bird_genus, genus_id from genus;
 
 select genus_name as bird_genus, genus_id from public.genus;
-	
+	
+select * from family where family_name='Дроздовые' or family_name='Синицевые';
+select * from family where family_name in ('Дроздовые', 'Синицевые');
+
+select * from family where family_name='Дроздовые' and family_name='Синицевые';
+
+select * from family where family_name like '%а%' or family_name like '%с%';
+
+

+ 10 - 0
docs/Script.sql

@@ -53,3 +53,13 @@ show search_path;
 table book_category;
 
 select |/225;
+
+-- Фильтрация данных
+
+
+select * from author where author_id=1;
+
+select * from author where name='Михаил Шолохов' and author_id=200;
+
+
+

+ 36 - 0
hardcore web development/11. SQL/Создание таблиц.md

@@ -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+$';
 ```