{"id":367794,"date":"2024-05-21T03:28:36","date_gmt":"2024-05-21T03:28:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=367794"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T03:28:36","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=367794","title":{"rendered":"<span>\u041c\u043e\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 SQL (SQLite) \u0441 \u0433\u043e\u0442\u043e\u0432\u044b\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440)<\/p>\n<p>\u041f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u043f\u043e SQL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u043b\u0430 \u043c\u043d\u0435, \u0434\u0430 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043d\u0435\u0451 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u044e.<\/p>\n<p>\u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f \u0421\u0423\u0411\u0414 SQLite, \u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0451 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0421\u0423\u0411\u0414.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0434\u0443\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0441 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c. \u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u2014 \u043b\u0438\u0441\u0442\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u0437. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430\u043c\u0438, \u0434\u043b\u0438\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u0441 \u043e\u043a\u043e\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 SQL \u0432 Python \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u0435\u043a <code>sqlite3<\/code>, <code>pandas<\/code>,  <code>polars<\/code>. \u042d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0435 \u043f\u043e\u0441\u043e\u0431\u0438\u0435 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f SQL.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u044f \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0432 \u0441\u0432\u043e\u0435\u043c <a href=\"https:\/\/t.me\/+dXZpK8lQ0lY4YjAy\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u043d\u0430\u043b\u0435 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/a>, \u0433\u0434\u0435 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0435\u0442\u043e\u0432, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043a\u043e\u0434\u043e\u043c. \u0410 <a href=\"https:\/\/t.me\/addlist\/qht-ouKSGaQwNjcy\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043f\u0430\u043f\u043a\u0430,<\/a> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.  <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/396\/104\/b28\/396104b284a2b3d8f63d69c0501eef13.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/396\/104\/b28\/396104b284a2b3d8f63d69c0501eef13.png\"\/><\/figure>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b SQL \u0437\u0430\u0431\u043e\u0442\u043b\u0438\u0432\u043e \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/gvwilson\/sql-tutorial\/raw\/main\/sql-tutorial.zip\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0435\u0451<\/a> \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0430\u0440\u0445\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 3 \u0433\u0440\u0443\u043f\u043f\u044b \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>.\/db\/*.db<\/code> \u2014 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 SQLite, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043d\u0438\u0436\u0435<\/p>\n<\/li>\n<li>\n<p><code>.\/src\/*.*<\/code> \u2014 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 Python<\/p>\n<\/li>\n<li>\n<p><code>.\/out\/*.*<\/code> \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/49e\/129\/c9a\/49e129c9a5cabfcd6264e8a449db33aa.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/49e\/129\/c9a\/49e129c9a5cabfcd6264e8a449db33aa.png\"\/><\/figure>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<p><a href=\"#0\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/a><br \/><a href=\"#1\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b SQL<\/a><br \/><a href=\"#2\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#3\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/a><br \/><a href=\"#4\" rel=\"noopener noreferrer nofollow\">\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/a><br \/><a href=\"#5\" rel=\"noopener noreferrer nofollow\">\u0415\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0432\u043e\u0434\u0430<\/a><br \/><a href=\"#6\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/a><br \/><a href=\"#7\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/a><br \/><a href=\"#8\" rel=\"noopener noreferrer nofollow\">\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438<\/a><br \/><a href=\"#9\" rel=\"noopener noreferrer nofollow\">\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/a><br \/><a href=\"#10\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#11\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0441 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/a><br \/><a href=\"#12\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0432\u043e\u0434 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WHERE<\/a><br \/><a href=\"#13\" rel=\"noopener noreferrer nofollow\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435\u043c<\/a><br \/><a href=\"#14\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c NULL \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#15\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 SQL<\/a><br \/><a href=\"#16\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 SQL<\/a><br \/><a href=\"#17\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 COUNT<\/a><br \/><a href=\"#18\" rel=\"noopener noreferrer nofollow\">\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430<\/a><br \/><a href=\"#19\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0441\u0435\u0431\u044f \u0432\u0435\u0434\u0443\u0442 \u043d\u0435\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#20\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u043e\u0440 \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a><br \/><a href=\"#21\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#22\" rel=\"noopener noreferrer nofollow\">\u0427\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434<\/a><br \/><a href=\"#23\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><br \/><a href=\"#24\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/a><br \/><a href=\"#25\" rel=\"noopener noreferrer nofollow\">\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435<\/a><br \/><a href=\"#26\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#27\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#28\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><br \/><a href=\"#29\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 JOIN<\/a><br \/><a href=\"#30\" rel=\"noopener noreferrer nofollow\">INNER JOIN<\/a><br \/><a href=\"#31\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 JOIN \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/a><br \/><a href=\"#32\" rel=\"noopener noreferrer nofollow\">LEFT JOIN<\/a><br \/><a href=\"#33\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 LEFT JOIN<\/a><br \/><a href=\"#34\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#35\" rel=\"noopener noreferrer nofollow\">SELECT DISTINCT \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 WHERE<\/a><br \/><a href=\"#36\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 WHERE \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 IN<\/a><br \/><a href=\"#37\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/a><br \/><a href=\"#38\" rel=\"noopener noreferrer nofollow\">\u0410\u0432\u0442\u043e\u0438\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u0438 PRIMARY KEY<\/a><br \/><a href=\"#39\" rel=\"noopener noreferrer nofollow\">\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 ALTER<\/a><br \/><a href=\"#40\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0442\u0430\u0440\u043e\u0439<\/a><br \/><a href=\"#41\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/a><br \/><a href=\"#42\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438<\/a><br \/><a href=\"#43\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f<\/a><br \/><a href=\"#44\" rel=\"noopener noreferrer nofollow\">CTE \u2014 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#45\" rel=\"noopener noreferrer nofollow\">\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e EXPLAIN<\/a><br \/><a href=\"#46\" rel=\"noopener noreferrer nofollow\">\u041d\u0443\u043c\u0435\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#47\" rel=\"noopener noreferrer nofollow\">\u0423\u0441\u043b\u043e\u0432\u0438\u044f if-else<\/a><br \/><a href=\"#48\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SELECT \u0438 CASE<\/a><br \/><a href=\"#49\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#50\" rel=\"noopener noreferrer nofollow\">\u0418\u0449\u0435\u043c \u043f\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE<\/a><br \/><a href=\"#51\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#52\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/a><br \/><a href=\"#53\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/a><br \/><a href=\"#54\" rel=\"noopener noreferrer nofollow\">\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 SQL<\/a><br \/><a href=\"#55\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/a><br \/><a href=\"#56\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#57\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><br \/><a href=\"#58\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u0430\u0442<\/a><br \/><a href=\"#59\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430 \u0434\u0435\u043d\u044c, \u0431\u0435\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432<\/a><br \/><a href=\"#60\" rel=\"noopener noreferrer nofollow\">JOIN \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u0441 \u0441\u043e\u0431\u043e\u0439 \u0436\u0435<\/a><br \/><a href=\"#61\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#62\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u0430\u0440<\/a><br \/><a href=\"#63\" rel=\"noopener noreferrer nofollow\">EXISTS<\/a><br \/><a href=\"#64\" rel=\"noopener noreferrer nofollow\">NOT EXISTS \u0432 SQL<\/a><br \/><a href=\"#65\" rel=\"noopener noreferrer nofollow\">\u041e\u043f\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0435 <\/a><br \/><a href=\"#66\" rel=\"noopener noreferrer nofollow\">\u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><br \/><a href=\"#67\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c PARTITION BY \u0432 SQL<\/a><br \/><a href=\"#68\" rel=\"noopener noreferrer nofollow\">\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 blob<\/a><br \/><a href=\"#69\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 JSON<\/a><br \/><a href=\"#70\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 JSON<\/a><br \/><a href=\"#71\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0443<\/a><br \/><a href=\"#72\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 JSON<\/a><br \/><a href=\"#73\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435<\/a><br \/><a href=\"#74\" rel=\"noopener noreferrer nofollow\">\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c JSON<\/a><br \/><a href=\"#75\" rel=\"noopener noreferrer nofollow\">Immediate If \u0432 SQL<\/a><br \/><a href=\"#76\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 VIEW \u0432 SQL<\/a><br \/><a href=\"#77\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 CHECK<\/a><br \/><a href=\"#78\" rel=\"noopener noreferrer nofollow\">TRANSACTION \u0432 SQL<\/a><br \/><a href=\"#79\" rel=\"noopener noreferrer nofollow\">ROLLBACK \u0432 SQL<\/a><br \/><a href=\"#80\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u043a\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ROLLBACK<\/a><br \/><a href=\"#81\" rel=\"noopener noreferrer nofollow\">\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#82\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430<\/a><br \/><a href=\"#83\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/a><br \/><a href=\"#84\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 bi_contact<\/a><br \/><a href=\"#85\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0433\u0440\u0443\u043f\u043f<\/a><br \/><a href=\"#86\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043a\u0438<\/a><br \/><a href=\"#87\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 SQL \u0432 Python \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 sqlite3<\/a><br \/><a href=\"#88\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 <\/a><br \/><a href=\"#89\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CREATE, INSERT, DELETE \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sqlite3<\/a><br \/><a href=\"#90\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#91\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 Python<\/a><br \/><a href=\"#92\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f SQLite \u0432 Python<\/a><br \/><a href=\"#93\" rel=\"noopener noreferrer nofollow\">Python \u0438 SQLite, \u0435\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/a><br \/><a href=\"#94\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u0442\u043e\u0439 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c<\/a><br \/><a href=\"#95\" rel=\"noopener noreferrer nofollow\">SQL \u0432 Jupyter Notebooks<\/a><br \/><a href=\"#96\" rel=\"noopener noreferrer nofollow\">Pandas \u0438 SQL<\/a><br \/><a href=\"#97\" rel=\"noopener noreferrer nofollow\">Polars \u0438 SQL<\/a><br \/><a href=\"#98\" rel=\"noopener noreferrer nofollow\">ORM<\/a><br \/><a href=\"#99\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 ORM<\/a><br \/><a href=\"#100\" rel=\"noopener noreferrer nofollow\">The end<\/a><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b6e\/b97\/426\/b6eb974264d3a5cdb8810667355bb79f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b6e\/b97\/426\/b6eb974264d3a5cdb8810667355bb79f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"0\" id=\"0\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/h3>\n<pre><code class=\"sql\">SELECT * FROM little_penguins; <\/code><\/pre>\n<pre><code>Adelie|Dream|37.2|18.1|178|3900|MALE Adelie|Dream|37.6|19.3|181|3300|FEMALE Gentoo|Biscoe|50|15.3|220|5550|MALE Adelie|Torgersen|37.3|20.5|199|3775|MALE Adelie|Biscoe|39.6|17.7|186|3500|FEMALE Gentoo|Biscoe|47.7|15|216|4750|FEMALE Adelie|Dream|36.5|18|182|3150|FEMALE Gentoo|Biscoe|42|13.5|210|4150|FEMALE Adelie|Torgersen|42.1|19.1|195|4000|MALE Gentoo|Biscoe|54.3|15.7|231|5650|MALE <\/code><\/pre>\n<ul>\n<li>\n<p>\u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0d\/73b\/cf0\/d0d73bcf07d2dc0d7d7c350d3eaf5e10.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d0d\/73b\/cf0\/d0d73bcf07d2dc0d7d7c350d3eaf5e10.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/admin_commands.sql\" rel=\"noopener noreferrer nofollow\">src\/admin_commands.sql<\/a><\/p>\n<pre><code class=\"sql\">.headers on  .mode markdown SELECT * FROM little_penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/admin_commands.out\" rel=\"noopener noreferrer nofollow\">out\/admin_commands.out<\/a><\/p>\n<pre><code>| species |  island   | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g |  sex   | |---------|-----------|----------------|---------------|-------------------|-------------|--------| | Adelie  | Dream     | 37.2           | 18.1          | 178               | 3900        | MALE   | | Adelie  | Dream     | 37.6           | 19.3          | 181               | 3300        | FEMALE | | Gentoo  | Biscoe    | 50             | 15.3          | 220               | 5550        | MALE   | | Adelie  | Torgersen | 37.3           | 20.5          | 199               | 3775        | MALE   | | Adelie  | Biscoe    | 39.6           | 17.7          | 186               | 3500        | FEMALE | | Gentoo  | Biscoe    | 47.7           | 15            | 216               | 4750        | FEMALE | | Adelie  | Dream     | 36.5           | 18            | 182               | 3150        | FEMALE | | Gentoo  | Biscoe    | 42             | 13.5          | 210               | 4150        | FEMALE | | Adelie  | Torgersen | 42.1           | 19.1          | 195               | 4000        | MALE   | | Gentoo  | Biscoe    | 54.3           | 15.7          | 231               | 5650        | MALE   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0440\u0435\u0436\u0438\u043c markdown; \u0432 <code>SQLite<\/code> \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 <code>.<\/code>, \u0430 \u0432 PostgreSQL \u0441 <code>\\<\/code><\/p>\n<\/li>\n<li>\n<p>\u043a\u0441\u0442\u0430\u0442\u0438, \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u044b \u0438\u043b\u0438 \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0435\u0441\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>.help<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9bf\/79f\/556\/9bf79f556e0e1fb43155755177faa03d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9bf\/79f\/556\/9bf79f556e0e1fb43155755177faa03d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/specify_columns.sql\" rel=\"noopener noreferrer nofollow\">src\/specify_columns.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        island,        sex FROM little_penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/specify_columns.out\" rel=\"noopener noreferrer nofollow\">out\/specify_columns.out<\/a><\/p>\n<pre><code>| species |  island   |  sex   | |---------|-----------|--------| | Adelie  | Dream     | MALE   | | Adelie  | Dream     | FEMALE | | Gentoo  | Biscoe    | MALE   | | Adelie  | Torgersen | MALE   | | Adelie  | Biscoe    | FEMALE | | Gentoo  | Biscoe    | FEMALE | | Adelie  | Dream     | FEMALE | | Gentoo  | Biscoe    | FEMALE | | Adelie  | Torgersen | MALE   | | Gentoo  | Biscoe    | MALE   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0438 <code>species<\/code>, <code>island<\/code>, <code>sex<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a71\/e64\/cf7\/a71e64cf7a8709b39f9213d36f5cb864.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a71\/e64\/cf7\/a71e64cf7a8709b39f9213d36f5cb864.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/sort.sql\" rel=\"noopener noreferrer nofollow\">src\/sort.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM little_penguins ORDER BY island ASC,          sex DESC; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/sort.out\" rel=\"noopener noreferrer nofollow\">out\/sort.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Gentoo  | MALE   | Biscoe    | | Gentoo  | MALE   | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Gentoo  | FEMALE | Biscoe    | | Gentoo  | FEMALE | Biscoe    | | Adelie  | MALE   | Dream     | | Adelie  | FEMALE | Dream     | | Adelie  | FEMALE | Dream     | | Adelie  | MALE   | Torgersen | | Adelie  | MALE   | Torgersen | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>island<\/code>, <code>sex<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>island<\/code> \u0432 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u043e\u0442 A \u043a Z)<\/p>\n<\/li>\n<li>\n<p>\u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>island<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c <code>sex<\/code> \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a \u043c\u0435\u043d\u044c\u0448\u0435\u043c\u0443 (\u043e\u0442 Z \u043a A)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/57f\/75d\/a56\/57f75da56b09b401fcf9799a331edffe.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/57f\/75d\/a56\/57f75da56b09b401fcf9799a331edffe.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/limit.sql\" rel=\"noopener noreferrer nofollow\">src\/limit.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM penguins ORDER BY species,          sex,          island LIMIT 10; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/limit.out\" rel=\"noopener noreferrer nofollow\">out\/limit.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Adelie  |        | Dream     | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e <code>species<\/code> \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f, \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>species<\/code> \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e <code>sex<\/code>, \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c <code>sex<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e <code>island<\/code><\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 10 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/551\/a66\/75c\/551a6675c3a7c98b59c7eb8f55165910.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/551\/a66\/75c\/551a6675c3a7c98b59c7eb8f55165910.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h3>\u0415\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0432\u043e\u0434\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/page.sql\" rel=\"noopener noreferrer nofollow\">src\/page.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM penguins ORDER BY species,          sex,          island LIMIT 10 OFFSET 3; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/page.out\" rel=\"noopener noreferrer nofollow\">out\/page.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p><code>OFFSET<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 <code>LIMIT<\/code> \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b 3 \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ad0\/357\/6c2\/ad03576c26f97786a500d03703892997.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ad0\/357\/6c2\/ad03576c26f97786a500d03703892997.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h3>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/distinct.sql\" rel=\"noopener noreferrer nofollow\">src\/distinct.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/distinct.out\" rel=\"noopener noreferrer nofollow\">out\/distinct.out<\/a><\/p>\n<pre><code>|  species  |  sex   |  island   | |-----------|--------|-----------| | Adelie    | MALE   | Torgersen | | Adelie    | FEMALE | Torgersen | | Adelie    |        | Torgersen | | Adelie    | FEMALE | Biscoe    | | Adelie    | MALE   | Biscoe    | | Adelie    | FEMALE | Dream     | | Adelie    | MALE   | Dream     | | Adelie    |        | Dream     | | Chinstrap | FEMALE | Dream     | | Chinstrap | MALE   | Dream     | | Gentoo    | FEMALE | Biscoe    | | Gentoo    | MALE   | Biscoe    | | Gentoo    |        | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT DISTINCT<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dfa\/7e9\/656\/dfa7e965653f366fea35e6fa5e51deb0.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dfa\/7e9\/656\/dfa7e965653f366fea35e6fa5e51deb0.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"7\" id=\"7\"><\/a><\/p>\n<h3>\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter.sql\" rel=\"noopener noreferrer nofollow\">src\/filter.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter.out\" rel=\"noopener noreferrer nofollow\">out\/filter.out<\/a><\/p>\n<pre><code>| species |  sex   | island | |---------|--------|--------| | Adelie  | FEMALE | Biscoe | | Adelie  | MALE   | Biscoe | | Gentoo  | FEMALE | Biscoe | | Gentoo  | MALE   | Biscoe | | Gentoo  |        | Biscoe | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 <code>penguins<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>island<\/code> \u0440\u0430\u0432\u043d\u043e <code>Biscoe<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eb4\/3dc\/a02\/eb43dca02cf9ce9bfa4ae8f85f5a753c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb4\/3dc\/a02\/eb43dca02cf9ce9bfa4ae8f85f5a753c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"8\" id=\"8\"><\/a><\/p>\n<h3>\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter_and.sql\" rel=\"noopener noreferrer nofollow\">src\/filter_and.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'   AND sex != 'MALE'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter_and.out\" rel=\"noopener noreferrer nofollow\">out\/filter_and.out<\/a><\/p>\n<pre><code>| species |  sex   | island | |---------|--------|--------| | Adelie  | FEMALE | Biscoe | | Gentoo  | FEMALE | Biscoe | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 <code>penguins<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>island<\/code> \u0440\u0430\u0432\u043d\u043e <code>Biscoe<\/code>, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f <code>sex<\/code> \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>MALE<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f47\/a20\/937\/f47a20937f4b96578aed9fbd3fe8e730.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f47\/a20\/937\/f47a20937f4b96578aed9fbd3fe8e730.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"9\" id=\"9\"><\/a><\/p>\n<h3>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/calculations.sql\" rel=\"noopener noreferrer nofollow\">src\/calculations.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT flipper_length_mm \/ 10.0,        body_mass_g \/ 1000.0 FROM penguins LIMIT 3; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/calculations.out\" rel=\"noopener noreferrer nofollow\">out\/calculations.out<\/a><\/p>\n<pre><code>| flipper_length_mm \/ 10.0 | body_mass_g \/ 1000.0 | |--------------------------|----------------------| | 18.1                     | 3.75                 | | 18.6                     | 3.8                  | | 19.5                     | 3.25                 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c 3 \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>flipper_length_mm<\/code>, \u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430 10.0, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>body_mass_g<\/code>, \u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430 1000.0<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/230\/c60\/974\/230c60974bcb9b976e6de0842a3efa8b.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/230\/c60\/974\/230c60974bcb9b976e6de0842a3efa8b.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"10\" id=\"10\"><\/a><\/p>\n<h3>\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/rename_columns.sql\" rel=\"noopener noreferrer nofollow\">src\/rename_columns.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT flipper_length_mm \/ 10.0 AS flipper_cm,        body_mass_g \/ 1000.0 AS weight_kg,        island AS where_found FROM penguins LIMIT 3; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/rename_columns.out\" rel=\"noopener noreferrer nofollow\">out\/rename_columns.out<\/a><\/p>\n<pre><code>| flipper_cm | weight_kg | where_found | |------------|-----------|-------------| | 18.1       | 3.75      | Torgersen   | | 18.6       | 3.8       | Torgersen   | | 19.5       | 3.25      | Torgersen   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0434\u0435\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>flipper_length_mm<\/code> \u043d\u0430 10.0, \u0434\u0435\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>body_mass_g<\/code> \u043d\u0430 1000.0<\/p>\n<\/li>\n<li>\n<p>\u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>flipper_length_mm<\/code> \u2014 \u0432 <code>flipper_cm<\/code>, <code>body_mass_g<\/code> \u2014 \u0432 <code>weight_kg<\/code>, <code>island<\/code> \u2014 \u0432 <code>where_found<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0435 3 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 SQL \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0430\u043a:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/15d\/787\/68c\/15d78768cfdd66ebb2d454932b052a74.png\" alt=\"dios_1\" width=\"602\" height=\"422\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/15d\/787\/68c\/15d78768cfdd66ebb2d454932b052a74.png\"\/><\/p>\n<div><figcaption>dios_1<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e18\/eae\/9df\/e18eae9df89d77a054853d0a40276c4d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e18\/eae\/9df\/e18eae9df89d77a054853d0a40276c4d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"11\" id=\"11\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0441 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/show_missing_values.sql\" rel=\"noopener noreferrer nofollow\">src\/show_missing_values.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT flipper_length_mm \/ 10.0 AS flipper_cm,        body_mass_g \/ 1000.0 AS weight_kg,        island AS where_found FROM penguins LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/show_missing_values.out\" rel=\"noopener noreferrer nofollow\">out\/show_missing_values.out<\/a><\/p>\n<pre><code>| flipper_cm | weight_kg | where_found | |------------|-----------|-------------| | 18.1       | 3.75      | Torgersen   | | 18.6       | 3.8       | Torgersen   | | 19.5       | 3.25      | Torgersen   | |            |           | Torgersen   | | 19.3       | 3.45      | Torgersen   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0434\u0435\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>flipper_length_mm<\/code> \u043d\u0430 10, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u043e\u0432\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>flipper_cm<\/code><\/p>\n<\/li>\n<li>\n<p>\u0434\u0435\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>body_mass_g<\/code> \u043d\u0430 1000 \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u043e\u0432\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>weight_kg<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c <code>island<\/code> \u0432 <code>where_found<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/88f\/dbe\/12c\/88fdbe12c99d087a5d8f70833305e6a3.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/88f\/dbe\/12c\/88fdbe12c99d087a5d8f70833305e6a3.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"12\" id=\"12\"><\/a><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WHERE<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter.sql\" rel=\"noopener noreferrer nofollow\">src\/filter.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter.out\" rel=\"noopener noreferrer nofollow\">out\/filter.out<\/a><\/p>\n<pre><code>| species |  sex   | island | |---------|--------|--------| | Adelie  | FEMALE | Biscoe | | Adelie  | MALE   | Biscoe | | Gentoo  | FEMALE | Biscoe | | Gentoo  | MALE   | Biscoe | | Gentoo  |        | Biscoe | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>sex<\/code>, <code>island<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>penguins<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>island<\/code> \u0440\u0430\u0432\u043d\u043e <code>'Biscoe'<\/code><\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/null_equality.sql\" rel=\"noopener noreferrer nofollow\">src\/null_equality.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'   AND sex = 'FEMALE'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/null_equality.out\" rel=\"noopener noreferrer nofollow\">out\/null_equality.out<\/a><\/p>\n<pre><code>| species |  sex   | island | |---------|--------|--------| | Adelie  | FEMALE | Biscoe | | Gentoo  | FEMALE | Biscoe | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>penguins<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>island<\/code> \u0440\u0430\u0432\u043d\u043e <code>'Biscoe'<\/code> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>sex<\/code> \u0440\u0430\u0432\u043d\u043e <code>'FEMALE'<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6e7\/88e\/fd5\/6e788efd5d282082cfb20bfe80219ec8.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e7\/88e\/fd5\/6e788efd5d282082cfb20bfe80219ec8.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"13\" id=\"13\"><\/a><\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435\u043c<\/h3>\n<ul>\n<li>\n<p>\u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f <code>!=<\/code> \u0442\u043e\u0436\u0435 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/null_inequality.sql\" rel=\"noopener noreferrer nofollow\">src\/null_inequality.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'   AND sex != 'FEMALE'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/null_inequality.out\" rel=\"noopener noreferrer nofollow\">out\/null_inequality.out<\/a><\/p>\n<pre><code>| species | sex  | island | |---------|------|--------| | Adelie  | MALE | Biscoe | | Gentoo  | MALE | Biscoe | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/810\/816\/569\/8108165697b25ca493fc191d0ba5c056.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/810\/816\/569\/8108165697b25ca493fc191d0ba5c056.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"14\" id=\"14\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c NULL \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/safe_null_equality.sql\" rel=\"noopener noreferrer nofollow\">src\/safe_null_equality.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM penguins WHERE sex IS NULL; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/safe_null_equality.out\" rel=\"noopener noreferrer nofollow\">out\/safe_null_equality.out<\/a><\/p>\n<pre><code>| species | sex |  island   | |---------|-----|-----------| | Adelie  |     | Torgersen | | Adelie  |     | Torgersen | | Adelie  |     | Torgersen | | Adelie  |     | Torgersen | | Adelie  |     | Torgersen | | Adelie  |     | Dream     | | Gentoo  |     | Biscoe    | | Gentoo  |     | Biscoe    | | Gentoo  |     | Biscoe    | | Gentoo  |     | Biscoe    | | Gentoo  |     | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>penguins<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>sex<\/code> \u043d\u0435\u0442 (<code>NULL<\/code>)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0439 SQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0432\u044b\u0448\u0435:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ec7\/9ed\/553\/ec79ed55361ea1231ae8b419f8b6138c.png\" alt=\"dios_2\" width=\"642\" height=\"322\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ec7\/9ed\/553\/ec79ed55361ea1231ae8b419f8b6138c.png\"\/><\/p>\n<div><figcaption>dios_2<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6cf\/683\/17f\/6cf68317f0fa74f9220b7b6526e513b6.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6cf\/683\/17f\/6cf68317f0fa74f9220b7b6526e513b6.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"15\" id=\"15\"><\/a><\/p>\n<h3>\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/simple_sum.sql\" rel=\"noopener noreferrer nofollow\">src\/simple_sum.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sum(body_mass_g) AS total_mass FROM penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/simple_sum.out\" rel=\"noopener noreferrer nofollow\">out\/simple_sum.out<\/a><\/p>\n<pre><code>| total_mass | |------------| | 1437000    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0438 <code>body_mass_g<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>total_mass<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/55c\/730\/046\/55c7300461feec2569c408beb54097f9.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/55c\/730\/046\/55c7300461feec2569c408beb54097f9.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"16\" id=\"16\"><\/a><\/p>\n<h3>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/common_aggregations.sql\" rel=\"noopener noreferrer nofollow\">src\/common_aggregations.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT MAX(bill_length_mm) AS longest_bill,        MIN(flipper_length_mm) AS shortest_flipper,        AVG(bill_length_mm) \/ AVG(bill_depth_mm) AS weird_ratio FROM penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/common_aggregations.out\" rel=\"noopener noreferrer nofollow\">out\/common_aggregations.out<\/a><\/p>\n<pre><code>| longest_bill | shortest_flipper |   weird_ratio    | |--------------|------------------|------------------| | 59.6         | 172              | 2.56087082530644 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>bill_length_mm<\/code>, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u043a <code>longest_bill<\/code><\/p>\n<\/li>\n<li>\n<p>\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0437 <code>flipper_length_mm<\/code>, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0438\u0437 <code>bill_length_mm<\/code>, \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0438\u0437 <code>bill_depth_mm<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f2c\/a77\/fd3\/f2ca77fd3af6820ef9a73eb57c509188.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f2c\/a77\/fd3\/f2ca77fd3af6820ef9a73eb57c509188.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"17\" id=\"17\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 COUNT<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/count_behavior.sql\" rel=\"noopener noreferrer nofollow\">src\/count_behavior.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT COUNT(*) AS count_star,        COUNT(sex) AS count_specific,        COUNT(DISTINCT sex) AS count_distinct FROM penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/count_behavior.out\" rel=\"noopener noreferrer nofollow\">out\/count_behavior.out<\/a><\/p>\n<pre><code>| count_star | count_specific | count_distinct | |------------|----------------|----------------| | 344        | 333            | 2              | <\/code><\/pre>\n<ul>\n<li>\n<p><code>COUNT(*)<\/code> \u2014 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>count_star<\/code><\/p>\n<\/li>\n<li>\n<p><code>COUNT(sex)<\/code> \u2014 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>sex<\/code><\/p>\n<\/li>\n<li>\n<p><code>COUNT(DISTINCT sex)<\/code> \u2014 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>sex<\/code> (\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0438\u0445 2: <code>MALE<\/code>, <code>FEMALE<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u0438 3 \u0447\u0438\u0441\u043b\u0430 \u043a\u0430\u043a <code>count_star<\/code>, <code>count_specific<\/code>, <code>count_distinct<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/275\/cb1\/9f2\/275cb19f29a7bd96dfc7d4183bb487ec.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/275\/cb1\/9f2\/275cb19f29a7bd96dfc7d4183bb487ec.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"18\" id=\"18\"><\/a><\/p>\n<h3>\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/simple_group.sql\" rel=\"noopener noreferrer nofollow\">src\/simple_group.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT AVG(body_mass_g) AS average_mass_g FROM penguins GROUP BY sex; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/simple_group.out\" rel=\"noopener noreferrer nofollow\">out\/simple_group.out<\/a><\/p>\n<pre><code>|  average_mass_g  | |------------------| | 4005.55555555556 | | 3862.27272727273 | | 4545.68452380952 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>penguins<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>body_mass_g<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a <code>average_mass_g<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c <code>sex<\/code> (\u0433\u0440\u0443\u043f\u043f\u044b <code>FEMALE<\/code>, <code>MALE<\/code>, <code>NULL<\/code>)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a77\/797\/cd0\/a77797cd06615c9677112dd42de0f83e.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a77\/797\/cd0\/a77797cd06615c9677112dd42de0f83e.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"19\" id=\"19\"><\/a><\/p>\n<h3>\u041a\u0430\u043a \u0441\u0435\u0431\u044f \u0432\u0435\u0434\u0443\u0442 \u043d\u0435\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/unaggregated_columns.sql\" rel=\"noopener noreferrer nofollow\">src\/unaggregated_columns.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sex,        AVG(body_mass_g) AS average_mass_g FROM penguins GROUP BY sex; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/unaggregated_columns.out\" rel=\"noopener noreferrer nofollow\">out\/unaggregated_columns.out<\/a><\/p>\n<pre><code>|  sex   |  average_mass_g  | |--------|------------------| |        | 4005.55555555556 | | FEMALE | 3862.27272727273 | | MALE   | 4545.68452380952 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0432\u0438\u0434\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0433\u0440\u0443\u043f\u043f, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 <code>AVG(body_mass_g)<\/code>, \u043d\u043e \u0438 <code>sex<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u0438\u0434\u0438\u043c 3 \u0433\u0440\u0443\u043f\u043f\u044b: <code>NULL<\/code>, <code>FEMALE<\/code>, <code>MALE<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fe4\/20c\/f45\/fe420cf4501fce64acd2d517ba0148c3.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fe4\/20c\/f45\/fe420cf4501fce64acd2d517ba0148c3.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"20\" id=\"20\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u043e\u0440 \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/arbitrary_in_aggregation.sql\" rel=\"noopener noreferrer nofollow\">src\/arbitrary_in_aggregation.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sex,        body_mass_g FROM penguins GROUP BY sex; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/arbitrary_in_aggregation.out\" rel=\"noopener noreferrer nofollow\">out\/arbitrary_in_aggregation.out<\/a><\/p>\n<pre><code>|  sex   | body_mass_g | |--------|-------------| |        |             | | FEMALE | 3800        | | MALE   | 3750        | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0437\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c <code>body_mass_g<\/code>, \u0430 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 SQL \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043b\u044e\u0431\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>body_mass_g<\/code>. \u0410\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u0435\u0435)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/44f\/570\/553\/44f570553a04e8d39bca0e16509cca81.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/44f\/570\/553\/44f570553a04e8d39bca0e16509cca81.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"21\" id=\"21\"><\/a><\/p>\n<h3>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter_aggregation.sql\" rel=\"noopener noreferrer nofollow\">src\/filter_aggregation.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sex,        AVG(body_mass_g) AS average_mass_g FROM penguins GROUP BY sex HAVING average_mass_g > 4000.0; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter_aggregation.out\" rel=\"noopener noreferrer nofollow\">out\/filter_aggregation.out<\/a><\/p>\n<pre><code>| sex  |  average_mass_g  | |------|------------------| |      | 4005.55555555556 | | MALE | 4545.68452380952 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>HAVING<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>WHERE<\/code> (\u044d\u0444\u0444\u0435\u043a\u0442 \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439), \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>average_mass_g<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 4000<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ca6\/a85\/84d\/ca6a8584dc99003d7926d4064d890c75.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca6\/a85\/84d\/ca6a8584dc99003d7926d4064d890c75.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"22\" id=\"22\"><\/a><\/p>\n<h3>\u0427\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/readable_aggregation.sql\" rel=\"noopener noreferrer nofollow\">src\/readable_aggregation.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sex,        ROUND(AVG(body_mass_g), 1) AS average_mass_g FROM penguins GROUP BY sex HAVING average_mass_g > 4000.0; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/readable_aggregation.out\" rel=\"noopener noreferrer nofollow\">out\/readable_aggregation.out<\/a><\/p>\n<pre><code>| sex  | average_mass_g | |------|----------------| |      | 4005.6         | | MALE | 4545.7         | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 <code>AVG(body_mass_g<\/code> \u0434\u043e 1 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>ROUND<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5bf\/340\/df6\/5bf340df6383542ddc44f95a5dbdbe10.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5bf\/340\/df6\/5bf340df6383542ddc44f95a5dbdbe10.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"23\" id=\"23\"><\/a><\/p>\n<h3>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter_aggregate_inputs.sql\" rel=\"noopener noreferrer nofollow\">src\/filter_aggregate_inputs.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT sex,        ROUND(            AVG(body_mass_g) FILTER (WHERE body_mass_g &lt; 4000.0),             1)         AS average_mass_g FROM penguins GROUP BY sex; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter_aggregate_inputs.out\" rel=\"noopener noreferrer nofollow\">out\/filter_aggregate_inputs.out<\/a><\/p>\n<pre><code>|  sex   | average_mass_g | |--------|----------------| |        | 3362.5         | | FEMALE | 3417.3         | | MALE   | 3752.5         | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>FILTER<\/code> \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>body_mass_g<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 4000<\/p>\n<\/li>\n<li>\n<p>\u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0434\u043e 1 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>average_mass_g<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e <code>sex<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0432\u044f\u0437\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/14a\/3f1\/d76\/14a3f1d76fdfb449f1b3d725d935fe6a.png\" alt=\"dios_3\" width=\"617\" height=\"307\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/14a\/3f1\/d76\/14a3f1d76fdfb449f1b3d725d935fe6a.png\"\/><\/p>\n<div><figcaption>dios_3<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0411\u0414 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/in_memory_db.sh\" rel=\"noopener noreferrer nofollow\">src\/in_memory_db.sh<\/a><\/p>\n<pre><code>sqlite3 :memory: <\/code><\/pre>\n<ul>\n<li>\n<p>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443 SQLite, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ca4\/2a6\/1d7\/ca42a61d7fd793149038038e3e1cd14d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca4\/2a6\/1d7\/ca42a61d7fd793149038038e3e1cd14d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"24\" id=\"24\"><\/a><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/create_work_job.sql\" rel=\"noopener noreferrer nofollow\">src\/create_work_job.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (name text NOT NULL,                   billable real NOT NULL);  CREATE TABLE work (person text NOT NULL,                    job text NOT NULL); <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>name<\/code> \u2014 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c (<code>NOT NULL<\/code>), <code>billable<\/code> \u2014 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>work<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>person<\/code> \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c, <code>job<\/code> \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e97\/615\/b43\/e97615b434eaa8703dc4d24d8b7766d4.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e97\/615\/b43\/e97615b434eaa8703dc4d24d8b7766d4.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"25\" id=\"25\"><\/a><\/p>\n<h3>\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/populate_work_job.sql\" rel=\"noopener noreferrer nofollow\">src\/populate_work_job.sql<\/a><\/p>\n<pre><code class=\"sql\">INSERT INTO job VALUES ('calibrate', 1.5),        ('clean', 0.5);  INSERT INTO work VALUES ('mik', 'calibrate'),        ('mik', 'clean'),        ('mik', 'complain'),        ('po', 'clean'),        ('po', 'complain'),        ('tay', 'complain'); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/insert_values.out\" rel=\"noopener noreferrer nofollow\">out\/insert_values.out<\/a><\/p>\n<pre><code>|   name    | billable | |-----------|----------| | calibrate | 1.5      | | clean     | 0.5      |  | person |    job    | |--------|-----------| | mik    | calibrate | | mik    | clean     | | mik    | complain  | | po     | clean     | | po     | complain  | | tay    | complain  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>job<\/code> \u043f\u0430\u0440\u0430\u043c\u0438 <code>name<\/code>&#8212;<code>billable<\/code>, \u0438 \u0442\u0430\u043a \u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>work<\/code> \u043f\u0430\u0440\u0430\u043c\u0438 <code>person<\/code>&#8212;<code>job<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e5c\/53f\/d23\/e5c53fd23149f90c38960b41b5d6b431.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e5c\/53f\/d23\/e5c53fd23149f90c38960b41b5d6b431.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"26\" id=\"26\"><\/a><\/p>\n<h3>\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/update_work_job.sql\" rel=\"noopener noreferrer nofollow\">src\/update_work_job.sql<\/a><\/p>\n<pre><code class=\"sql\">UPDATE work SET person = \"tae\" WHERE person = \"tay\"; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/update_rows.out\" rel=\"noopener noreferrer nofollow\">out\/update_rows.out<\/a><\/p>\n<pre><code>| person |    job    | |--------|-----------| | mik    | calibrate | | mik    | clean     | | mik    | complain  | | po     | clean     | | po     | complain  | | tae    | complain  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 <code>\"tay\"<\/code> \u043d\u0430 <code>\"tae\"<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/72a\/2c8\/8cd\/72a2c88cddb10e617a0e96b87054c7d1.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/72a\/2c8\/8cd\/72a2c88cddb10e617a0e96b87054c7d1.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"27\" id=\"27\"><\/a><\/p>\n<h3>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/delete_rows.sql\" rel=\"noopener noreferrer nofollow\">src\/delete_rows.sql<\/a><\/p>\n<pre><code class=\"sql\">DELETE FROM work WHERE person = \"tae\"; SELECT * FROM work; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/delete_rows.out\" rel=\"noopener noreferrer nofollow\">out\/delete_rows.out<\/a><\/p>\n<pre><code>| person |    job    | |--------|-----------| | mik    | calibrate | | mik    | clean     | | mik    | complain  | | po     | clean     | | po     | complain  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>person<\/code> \u0440\u0430\u0432\u043d\u043e <code>\"tae\"<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f78\/c31\/b20\/f78c31b201b6c9af7ddfed6589ea7157.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f78\/c31\/b20\/f78c31b201b6c9af7ddfed6589ea7157.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"28\" id=\"28\"><\/a><\/p>\n<h3>\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/backing_up.sql\" rel=\"noopener noreferrer nofollow\">src\/backing_up.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE backup (person text NOT NULL,                      job text NOT NULL);                       INSERT INTO backup SELECT person,        job FROM work WHERE person = 'tae';  DELETE FROM work WHERE person = 'tae';  SELECT * FROM backup; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/backing_up.out\" rel=\"noopener noreferrer nofollow\">out\/backing_up.out<\/a><\/p>\n<pre><code>| person |   job    | |--------|----------| | tae    | complain | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>backup<\/code> c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>person<\/code> \u0438 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c <code>backup<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>person<\/code> \u0438 <code>job<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>work<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>person<\/code> \u0440\u0430\u0432\u043d\u043e <code>'tae'<\/code><\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 <code>work<\/code> \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>person<\/code> \u0440\u0430\u0432\u043d\u044b\u043c <code>'tae'<\/code><\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>backup<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0432\u044f\u0437\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438:<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/77a\/830\/aef\/77a830aef6742b2c67bddd6934fba68e.png\" alt=\"dios_4\" width=\"813\" height=\"352\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/77a\/830\/aef\/77a830aef6742b2c67bddd6934fba68e.png\"\/><\/p>\n<div><figcaption>dios_4<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/138\/126\/5b9\/1381265b9d5e4a762968ac3059d45046.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/138\/126\/5b9\/1381265b9d5e4a762968ac3059d45046.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"29\" id=\"29\"><\/a><\/p>\n<h3>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 JOIN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/cross_join.sql\" rel=\"noopener noreferrer nofollow\">src\/cross_join.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM work CROSS JOIN job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/cross_join.out\" rel=\"noopener noreferrer nofollow\">out\/cross_join.out<\/a><\/p>\n<pre><code>| person |    job    |   name    | billable | |--------|-----------|-----------|----------| | mik    | calibrate | calibrate | 1.5      | | mik    | calibrate | clean     | 0.5      | | mik    | clean     | calibrate | 1.5      | | mik    | clean     | clean     | 0.5      | | mik    | complain  | calibrate | 1.5      | | mik    | complain  | clean     | 0.5      | | po     | clean     | calibrate | 1.5      | | po     | clean     | clean     | 0.5      | | po     | complain  | calibrate | 1.5      | | po     | complain  | clean     | 0.5      | | tay    | complain  | calibrate | 1.5      | | tay    | complain  | clean     | 0.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0434\u0435\u043b\u0430\u0435\u043c <code>CROSS JOIN<\/code> \u0434\u043b\u044f 2 \u0442\u0430\u0431\u043b\u0438\u0446 <code>work<\/code> \u0438 <code>job<\/code> \u2014 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u044d\u0442\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 (\u0435\u0441\u043b\u0438 \u0432 <code>work<\/code> 3 \u0441\u0442\u0440\u043e\u043a\u0438, \u0430 \u0432 <code>job<\/code> 4 \u0441\u0442\u0440\u043e\u043a\u0438, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c 4 \u22c5 3 = 12 \u0441\u0442\u0440\u043e\u043a)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2ca\/3b3\/e5c\/2ca3b3e5c666d4072fca50a3b7c3b04f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2ca\/3b3\/e5c\/2ca3b3e5c666d4072fca50a3b7c3b04f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"30\" id=\"30\"><\/a><\/p>\n<h3>INNER JOIN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/inner_join.sql\" rel=\"noopener noreferrer nofollow\">src\/inner_join.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM work INNER JOIN job ON work.job = job.name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/inner_join.out\" rel=\"noopener noreferrer nofollow\">out\/inner_join.out<\/a><\/p>\n<pre><code>| person |    job    |   name    | billable | |--------|-----------|-----------|----------| | mik    | calibrate | calibrate | 1.5      | | mik    | clean     | clean     | 0.5      | | po     | clean     | clean     | 0.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c 2 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>work<\/code> \u0438 <code>job<\/code> \u2014 \u0431\u0435\u0440\u0451\u043c \u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0438, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>job<\/code> \u0438\u0437 <code>work<\/code> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>name<\/code> \u0438\u0437 <code>job<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b6e\/b95\/e67\/b6eb95e67ab3fa159d7854ecb3f1f059.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b6e\/b95\/e67\/b6eb95e67ab3fa159d7854ecb3f1f059.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"31\" id=\"31\"><\/a><\/p>\n<h3>\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 JOIN \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/aggregate_join.sql\" rel=\"noopener noreferrer nofollow\">src\/aggregate_join.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT work.person,        SUM(job.billable) AS pay FROM work INNER JOIN job ON work.job = job.name GROUP BY work.person; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/aggregate_join.out\" rel=\"noopener noreferrer nofollow\">out\/aggregate_join.out<\/a><\/p>\n<pre><code>| person | pay | |--------|-----| | mik    | 2.0 | | po     | 0.5 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 <code>work<\/code> \u0438 <code>job<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>job<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>work<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <code>name<\/code> \u0432 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>billable<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>job<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>person<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>work<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c <code>person<\/code> \u0438\u0437 <code>work<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/621\/408\/76e\/62140876e221e997f3dde4d8b8c905df.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/621\/408\/76e\/62140876e221e997f3dde4d8b8c905df.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"32\" id=\"32\"><\/a><\/p>\n<h3>LEFT JOIN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/left_join.sql\" rel=\"noopener noreferrer nofollow\">src\/left_join.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM work LEFT JOIN job ON work.job = job.name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/left_join.out\" rel=\"noopener noreferrer nofollow\">out\/left_join.out<\/a><\/p>\n<pre><code>| person |    job    |   name    | billable | |--------|-----------|-----------|----------| | mik    | calibrate | calibrate | 1.5      | | mik    | clean     | clean     | 0.5      | | mik    | complain  |           |          | | po     | clean     | clean     | 0.5      | | po     | complain  |           |          | | tay    | complain  |           |          | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>work<\/code> \u0438 <code>job<\/code> \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>work<\/code> \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>job<\/code>, \u0442\u043e \u043e\u043d\u0438 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 (<code>NULL<\/code>) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>LEFT JOIN<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>work<\/code> \u0431\u0443\u0434\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u043f\u0440\u0430\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>job<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5b9\/2f4\/491\/5b92f449142e3469ebf656a0ecec83dd.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b9\/2f4\/491\/5b92f449142e3469ebf656a0ecec83dd.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"33\" id=\"33\"><\/a><\/p>\n<h3>\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 LEFT JOIN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/aggregate_left_join.sql\" rel=\"noopener noreferrer nofollow\">src\/aggregate_left_join.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT work.person,        sum(job.billable) AS pay FROM work LEFT JOIN job ON work.job = job.name GROUP BY work.person; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/aggregate_left_join.out\" rel=\"noopener noreferrer nofollow\">out\/aggregate_left_join.out<\/a><\/p>\n<pre><code>| person | pay | |--------|-----| | mik    | 2.0 | | po     | 0.5 | | tay    |     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>billable<\/code> \u0438\u0437 <code>job<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a <code>pay<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>LEFT JOIN<\/code>, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <code>work<\/code> \u0432 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>person<\/code> \u0438\u0437 <code>work<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0432\u044f\u0437\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438:<\/strong><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf7\/d2b\/6ab\/cf7d2b6ab00f8c8873746f9e93f73462.png\" alt=\"dios_5\" width=\"472\" height=\"322\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf7\/d2b\/6ab\/cf7d2b6ab00f8c8873746f9e93f73462.png\"\/><\/p>\n<div><figcaption>dios_5<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c6a\/335\/763\/c6a33576357a1a1cf9b39d98da513eb5.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c6a\/335\/763\/c6a33576357a1a1cf9b39d98da513eb5.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"34\" id=\"34\"><\/a><\/p>\n<h3>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/coalesce.sql\" rel=\"noopener noreferrer nofollow\">src\/coalesce.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT work.person,        COALESCE(SUM(job.billable), 0.0) AS pay FROM work  LEFT JOIN job ON work.job = job.name GROUP BY work.person; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/coalesce.out\" rel=\"noopener noreferrer nofollow\">out\/coalesce.out<\/a><\/p>\n<pre><code>| person | pay | |--------|-----| | mik    | 2.0 | | po     | 0.5 | | tay    | 0.0 | <\/code><\/pre>\n<ul>\n<li>\n<p><code>COALESCE<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b <code>NULL<\/code> \u043d\u0430 0.0, \u0435\u0441\u043b\u0438 \u0441\u0443\u043c\u043c\u0430 <code>billable<\/code> \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e <code>person<\/code> \u0440\u0430\u0432\u043d\u0430 <code>NULL<\/code><\/p>\n<\/li>\n<li>\n<p><code>LEFT JOIN<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>work<\/code> \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>person<\/code> \u0438\u0437 <code>work<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1bc\/bee\/a89\/1bcbeea8912c19f8c522d1bfe411c234.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1bc\/bee\/a89\/1bcbeea8912c19f8c522d1bfe411c234.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"35\" id=\"35\"><\/a><\/p>\n<h3>SELECT DISTINCT \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 WHERE<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/negate_incorrectly.sql\" rel=\"noopener noreferrer nofollow\">src\/negate_incorrectly.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT person FROM work WHERE job != 'calibrate'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/negate_incorrectly.out\" rel=\"noopener noreferrer nofollow\">out\/negate_incorrectly.out<\/a><\/p>\n<pre><code>| person | |--------| | mik    | | po     | | tay    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>person<\/code>, \u0433\u0434\u0435 \u043f\u043e\u043b\u0435 <code>job<\/code> \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>calibrate<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d56\/fee\/a7b\/d56feea7b1b1df24c4cf1ca1abdfcd38.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d56\/fee\/a7b\/d56feea7b1b1df24c4cf1ca1abdfcd38.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"36\" id=\"36\"><\/a><\/p>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 WHERE \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 IN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/set_membership.sql\" rel=\"noopener noreferrer nofollow\">src\/set_membership.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM work WHERE person NOT IN ('mik',                      'tay'); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/set_membership.out\" rel=\"noopener noreferrer nofollow\">out\/set_membership.out<\/a><\/p>\n<pre><code>| person |   job    | |--------|----------| | po     | clean    | | po     | complain | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <code>work<\/code>, \u0433\u0434\u0435 <code>person<\/code> \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>'mik'<\/code> \u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u043e <code>'tay'<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7af\/7a7\/409\/7af7a74090582fbf216564a0c7947b5a.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7af\/7a7\/409\/7af7a74090582fbf216564a0c7947b5a.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"37\" id=\"37\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/subquery_set.sql\" rel=\"noopener noreferrer nofollow\">src\/subquery_set.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT person FROM work WHERE person not in     (SELECT DISTINCT person      FROM work      WHERE job = 'calibrate'); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/subquery_set.out\" rel=\"noopener noreferrer nofollow\">out\/subquery_set.out<\/a><\/p>\n<pre><code>| person | |--------| | po     | | tay    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>person<\/code> \u0438\u0437 <code>work<\/code>, \u0433\u0434\u0435 \u0432 \u043f\u043e\u043b\u0435 <code>job<\/code> \u0441\u0442\u043e\u0438\u0442 <code>'calibrate'<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u043d\u0435\u0448\u043d\u0438\u0439, \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>person<\/code>, \u0433\u0434\u0435 <code>person<\/code> \u043d\u0435 \u0440\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u0438\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3c2\/321\/f4a\/3c2321f4a96a7a719bfe42afa9e2bfc7.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c2\/321\/f4a\/3c2321f4a96a7a719bfe42afa9e2bfc7.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"38\" id=\"38\"><\/a><\/p>\n<h3>\u0410\u0432\u0442\u043e\u0438\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u0438 PRIMARY KEY<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/autoincrement.sql\" rel=\"noopener noreferrer nofollow\">src\/autoincrement.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE person (ident integer PRIMARY KEY autoincrement,                      name text NOT NULL); INSERT INTO person VALUES (NULL, 'mik'),        (NULL, 'po'),        (NULL, 'tay');  SELECT * FROM person; INSERT INTO person VALUES (1, \"prevented\"); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/autoincrement.out\" rel=\"noopener noreferrer nofollow\">out\/autoincrement.out<\/a><\/p>\n<pre><code>| ident | name | |-------|------| | 1     | mik  | | 2     | po   | | 3     | tay  | Runtime error near line 12: UNIQUE constraint failed: person.ident (19) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>person<\/code> \u0441 2 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>ident<\/code> \u0441 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, <code>name<\/code> \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438; \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>ident<\/code> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u043a <code>PRIMARY KEY<\/code>, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>person<\/code> 3 \u043f\u0430\u0440\u044b <code>ident<\/code>&#8212;<code>name<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043f\u0430\u0440\u0443 <code>(1, \"prevented\")<\/code> \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 <code>indent<\/code> \u0440\u0430\u0432\u043d\u044b\u043c 1<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430:<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/sequence_table.sql\" rel=\"noopener noreferrer nofollow\">src\/sequence_table.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM sqlite_sequence; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/sequence_table.out\" rel=\"noopener noreferrer nofollow\">out\/sequence_table.out<\/a><\/p>\n<pre><code>|  name  | seq | |--------|-----| | person | 3   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0411\u0414 SQLite<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bc5\/432\/fde\/bc5432fde58e0fd3c659147e3c28a6a4.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc5\/432\/fde\/bc5432fde58e0fd3c659147e3c28a6a4.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"39\" id=\"39\"><\/a><\/p>\n<h3>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 ALTER<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/alter_tables.sql\" rel=\"noopener noreferrer nofollow\">src\/alter_tables.sql<\/a><\/p>\n<pre><code class=\"sql\">ALTER TABLE job ADD ident integer NOT NULL DEFAULT -1;  UPDATE job SET ident = 1 WHERE name = 'calibrate';  UPDATE job SET ident = 2 WHERE name = 'clean';  SELECT * FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/alter_tables.out\" rel=\"noopener noreferrer nofollow\">out\/alter_tables.out<\/a><\/p>\n<pre><code>|   name    | billable | ident | |-----------|----------|-------| | calibrate | 1.5      | 1     | | clean     | 0.5      | 2     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>ident<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>job<\/code>; \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c; \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>-1<\/code> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/p>\n<\/li>\n<li>\n<p>\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>ident<\/code> \u0440\u0430\u0432\u043d\u044b\u043c 1 \u0442\u0430\u043c, \u0433\u0434\u0435 <code>name<\/code> \u0440\u0430\u0432\u0435\u043d <code>'calibrate'<\/code><\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>ident<\/code> \u0440\u0430\u0432\u043d\u044b\u043c 2 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 <code>name<\/code> \u0440\u0430\u0432\u0435\u043d <code>clean<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/790\/449\/8e0\/7904498e0feaff44fb359a7a6f5f83df.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/790\/449\/8e0\/7904498e0feaff44fb359a7a6f5f83df.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"40\" id=\"40\"><\/a><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0442\u0430\u0440\u043e\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/insert_select.sql\" rel=\"noopener noreferrer nofollow\">src\/insert_select.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE new_work (person_id integer NOT NULL,                        job_id integer NOT NULL,                        FOREIGN key(person_id) REFERENCES person(ident),                        FOREIGN key(job_id) REFERENCES job(ident));  INSERT INTO new_work SELECT person.ident AS person_id,        job.ident AS job_id FROM (person       JOIN work        ON person.name = work.person)        JOIN job ON job.name = work.job;  SELECT * FROM new_work; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/insert_select.out\" rel=\"noopener noreferrer nofollow\">out\/insert_select.out<\/a><\/p>\n<pre><code>| person_id | job_id | |-----------|--------| | 1         | 1      | | 1         | 2      | | 2         | 2      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>new_work<\/code> \u0441 2 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>person_id<\/code> \u0438 <code>job_id<\/code>; \u043e\u0431\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>2 <code>FOREIGN KEY<\/code> \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>person_id<\/code> \u0438 <code>job_id<\/code> \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>new_work<\/code> \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>ident<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 <code>person<\/code> \u0438 <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>new_work<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>SELECT<\/code><\/p>\n<\/li>\n<li>\n<p><code>FROM (person JOIN work ON person.name = work.person)<\/code> \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 <code>person<\/code> \u0438 <code>work<\/code> \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>name<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>person<\/code> \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>person<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>work<\/code><\/p>\n<\/li>\n<li>\n<p><code>JOIN job ON job.name = work.job<\/code> \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>job<\/code> \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>name<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>job<\/code> \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>job<\/code> \u0432 <code>work<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ef3\/f83\/f94\/ef3f83f947ba34975dfa99d526824d6f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ef3\/f83\/f94\/ef3f83f947ba34975dfa99d526824d6f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"41\" id=\"41\"><\/a><\/p>\n<h3>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/drop_table.sql\" rel=\"noopener noreferrer nofollow\">src\/drop_table.sql<\/a><\/p>\n<pre><code class=\"sql\">DROP TABLE work; ALTER TABLE new_work RENAME TO work; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0435\u043c <code>work<\/code> \u0438\u0437 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>new_work<\/code> \u043d\u0430 <code>work<\/code><\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/drop_table.out\" rel=\"noopener noreferrer nofollow\">out\/drop_table.out<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (ident integer PRIMARY KEY autoincrement,                                             name text NOT NULL,                                             billable real NOT NULL); CREATE TABLE sqlite_sequence(name,                              seq);  CREATE TABLE person (ident integer PRIMARY KEY autoincrement,                                                name text NOT NULL);  CREATE TABLE IF NOT EXISTS \"work\" (person_id integer NOT NULL,                                    job_id integer NOT NULL,                                    FOREIGN key(person_id) REFERENCES person(ident),                                    FOREIGN key(job_id) REFERENCES job(ident)); <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 3 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438: <code>ident<\/code> \u0445\u0440\u0430\u043d\u0438\u0442 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 (<code>PRIMARY KEY<\/code>) \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f (autoincrement);<\/p>\n<p><code>name<\/code> \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c (<code>NOT NULL<\/code>);<\/p>\n<p><code>billable<\/code> \u2014 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>sqlite_sequence<\/code> \u0441 2 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438: <code>name<\/code> \u0438 <code>seq<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>person<\/code> \u0441 2 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438: <code>ident<\/code> \u2014 \u0445\u0440\u0430\u043d\u0438\u0442 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f (autoincrement), <code>name<\/code> \u2014 \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u0435\u043a\u0441\u0442, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>work<\/code> \u0441 4 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438: <code>person_id<\/code> &#8212; \u0445\u0440\u0430\u043d\u0438\u0442 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c; \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>job_id<\/code><\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 <code>person_id<\/code> \u0441 <code>ident<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>person<\/code> \u0438 <code>job_id<\/code> \u0441 <code>ident<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>job<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/50c\/681\/cf5\/50c681cf52afe351df4e5068bc9ad16c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/50c\/681\/cf5\/50c681cf52afe351df4e5068bc9ad16c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"42\" id=\"42\"><\/a><\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/compare_individual_aggregate.sql\" rel=\"noopener noreferrer nofollow\">src\/compare_individual_aggregate.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT body_mass_g FROM   penguins WHERE  body_mass_g > (SELECT AVG(body_mass_g)                       FROM   penguins) LIMIT  5;  <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/compare_individual_aggregate.out\" rel=\"noopener noreferrer nofollow\">out\/compare_individual_aggregate.out<\/a><\/p>\n<pre><code>| body_mass_g | |-------------| | 4675        | | 4250        | | 4400        | | 4500        | | 4650        | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>body_mass_g<\/code> \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>body_mass_g<\/code> \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9e3\/b8f\/4fb\/9e3b8f4fb0a0ba724bab77aeb46ef68f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e3\/b8f\/4fb\/9e3b8f4fb0a0ba724bab77aeb46ef68f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"43\" id=\"43\"><\/a><\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/compare_within_groups.sql\" rel=\"noopener noreferrer nofollow\">src\/compare_within_groups.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT penguins.species,        penguins.body_mass_g,        Round(averaged.avg_mass_g, 1) AS avg_mass_g FROM   penguins        JOIN (SELECT species,                     Avg(body_mass_g) AS avg_mass_g              FROM   penguins              GROUP  BY species) AS averaged          ON penguins.species = averaged.species WHERE  penguins.body_mass_g > averaged.avg_mass_g LIMIT  5;  <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/compare_within_groups.out\" rel=\"noopener noreferrer nofollow\">out\/compare_within_groups.out<\/a><\/p>\n<pre><code>| species | body_mass_g | avg_mass_g | |---------|-------------|------------| | Adelie  | 3750        | 3700.7     | | Adelie  | 3800        | 3700.7     | | Adelie  | 4675        | 3700.7     | | Adelie  | 4250        | 3700.7     | | Adelie  | 3800        | 3700.7     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code> \u0438 <code>body_mass_g<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043c\u0430\u0441\u0441\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0434\u043e 1 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>penguins<\/code> \u043f\u043e \u043f\u043e\u043b\u044e <code>species<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0438, \u0433\u0434\u0435 \u043c\u0430\u0441\u0441\u0430 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u043c\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u0438\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d8f\/c50\/4fd\/d8fc504fd98c42c7fce78c2927a57a27.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d8f\/c50\/4fd\/d8fc504fd98c42c7fce78c2927a57a27.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"44\" id=\"44\"><\/a><\/p>\n<h3>CTE \u2014 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/common_table_expressions.sql\" rel=\"noopener noreferrer nofollow\">src\/common_table_expressions.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH grouped AS   (SELECT species,           avg(body_mass_g) AS avg_mass_g    FROM penguins    GROUP BY species) SELECT penguins.species,        penguins.body_mass_g,        round(grouped.avg_mass_g, 1) AS avg_mass_g FROM penguins JOIN grouped WHERE penguins.body_mass_g > grouped.avg_mass_g LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/common_table_expressions.out\" rel=\"noopener noreferrer nofollow\">out\/common_table_expressions.out<\/a><\/p>\n<pre><code>| species | body_mass_g | avg_mass_g | |---------|-------------|------------| | Adelie  | 3750        | 3700.7     | | Adelie  | 3800        | 3700.7     | | Adelie  | 4675        | 3700.7     | | Adelie  | 4250        | 3700.7     | | Adelie  | 3800        | 3700.7     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>grouped<\/code> (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>WITH<\/code>), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043c\u0430\u0441\u0441\u0443 \u0442\u0435\u043b\u0430 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 (<code>AVG(body_mass_g)<\/code>) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0438\u0437 <code>penguins<\/code> (<code>GROUP BY species<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 <code>penguins<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b: <code>species<\/code>, <code>body_mass_g<\/code>; \u0438 \u0438\u0437 \u0438\u0437 \u043e\u0431\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>grouped<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c <code>avg_mass_g<\/code>, \u043e\u043a\u0440\u0443\u0433\u043b\u0451\u043d\u043d\u043e\u0435 \u0434\u043e 1 \u0437\u043d\u0430\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c <code>penguins<\/code> \u0441 \u043e\u0431\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>grouped<\/code> (\u0447\u0435\u0440\u0435\u0437 <code>JOIN<\/code>); \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u043c\u0430\u0441\u0441\u0430 \u0442\u0435\u043b\u0430 \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u0438\u0434\u0430<\/p>\n<\/li>\n<li>\n<p><code>WHERE<\/code> \u2014 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c; \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0430\u0441\u0441\u0430 \u0442\u0435\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u043c\u0430\u0441\u0441\u044b \u0438\u0445 \u0432\u0438\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1a0\/f4b\/24a\/1a0f4b24ae05e77269560b64e7ce1195.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1a0\/f4b\/24a\/1a0f4b24ae05e77269560b64e7ce1195.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"45\" id=\"45\"><\/a><\/p>\n<h3>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e EXPLAIN<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/explain_query_plan.sql\" rel=\"noopener noreferrer nofollow\">src\/explain_query_plan.sql<\/a><\/p>\n<pre><code class=\"sql\">EXPLAIN query PLAN SELECT species,        AVG(body_mass_g) FROM penguins GROUP BY species; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/explain_query_plan.out\" rel=\"noopener noreferrer nofollow\">out\/explain_query_plan.out<\/a><\/p>\n<pre><code>QUERY PLAN |--SCAN penguins `--USE TEMP B-TREE FOR GROUP BY <\/code><\/pre>\n<ul>\n<li>\n<p><code>EXPLAIN query PLAN<\/code> \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>species<\/code>, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 body_mass_g \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0438\u0437 <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p><code>GROUP BY species<\/code> \u2014 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>species<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a38\/958\/ef1\/a38958ef163ddf108f6c6fb0d0dd8e80.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a38\/958\/ef1\/a38958ef163ddf108f6c6fb0d0dd8e80.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"46\" id=\"46\"><\/a><\/p>\n<h3>\u041d\u0443\u043c\u0435\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/h3>\n<ul>\n<li>\n<p>\u043a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>rowid<\/code> \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/rowid.sql\" rel=\"noopener noreferrer nofollow\">src\/rowid.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT rowid, species, island FROM penguins LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/rowid.out\" rel=\"noopener noreferrer nofollow\">out\/rowid.out<\/a><\/p>\n<pre><code>| rowid | species |  island   | |-------|---------|-----------| | 1     | Adelie  | Torgersen | | 2     | Adelie  | Torgersen | | 3     | Adelie  | Torgersen | | 4     | Adelie  | Torgersen | | 5     | Adelie  | Torgersen | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/497\/97d\/ab0\/49797dab0d3a319ce4af979f6b3baa08.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/497\/97d\/ab0\/49797dab0d3a319ce4af979f6b3baa08.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"47\" id=\"47\"><\/a><\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u044f if-else<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/if_else.sql\" rel=\"noopener noreferrer nofollow\">src\/if_else.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH sized_penguins AS   (SELECT species,           IIF(body_mass_g &lt; 3500, 'small', 'large') AS size    FROM penguins) SELECT species,        size,        count(*) AS num FROM sized_penguins GROUP BY species,          size ORDER BY species,          num; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/if_else.out\" rel=\"noopener noreferrer nofollow\">out\/if_else.out<\/a><\/p>\n<pre><code>|  species  | size  | num | |-----------|-------|-----| | Adelie    | small | 54  | | Adelie    | large | 98  | | Chinstrap | small | 17  | | Chinstrap | large | 51  | | Gentoo    | large | 124 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>sized_penguins<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430: <code>species<\/code> \u0438 <code>size<\/code><\/p>\n<\/li>\n<li>\n<p><code>size<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f: \u0435\u0441\u043b\u0438 <code>body_mass_g<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 3500, \u0442\u043e \u043e\u043d \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f <code>'small'<\/code>, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; <code>'large'<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code> \u0438 <code>size<\/code> \u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>sized_penguins<\/code>, \u0430 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 <code>species<\/code> \u0438 <code>size<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>count(*)<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 (<code>GROUP BY<\/code>) \u043f\u043e <code>species<\/code> \u0438 <code>size<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/810\/d01\/d34\/810d01d345a9c553eb1181b3b3bd3b78.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/810\/d01\/d34\/810d01d345a9c553eb1181b3b3bd3b78.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"48\" id=\"48\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SELECT \u0438 CASE<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/case_when.sql\" rel=\"noopener noreferrer nofollow\">src\/case_when.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH sized_penguins AS   (SELECT species,           CASE               WHEN body_mass_g &lt; 3500 THEN 'small'               WHEN body_mass_g &lt; 5000 THEN 'medium'               ELSE 'large'           END AS SIZE    FROM penguins) SELECT species,        SIZE,        count(*) AS num FROM sized_penguins GROUP BY species,          SIZE ORDER BY species,          num; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/case_when.out\" rel=\"noopener noreferrer nofollow\">out\/case_when.out<\/a><\/p>\n<pre><code>|  species  |  size  | num | |-----------|--------|-----| | Adelie    | large  | 1   | | Adelie    | small  | 54  | | Adelie    | medium | 97  | | Chinstrap | small  | 17  | | Chinstrap | medium | 51  | | Gentoo    | medium | 56  | | Gentoo    | large  | 68  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432 \u0431\u043b\u043e\u043a\u0435 <code>WITH<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>sized_penguins<\/code>, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <code>species<\/code> \u0438 <code>size<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 <code>body_mass_g<\/code><\/p>\n<\/li>\n<li>\n<p><code>CASE<\/code> \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u043d\u0430 3 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438: <code>'small'<\/code>, <code>'medium'<\/code> \u0438 <code>'large'<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u043c\u0430\u0441\u0441\u044b<\/p>\n<\/li>\n<li>\n<p>\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435 <code>SELECT<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u0438\u0434 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430, \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (<code>num<\/code>) \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 <code>sized_penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0432\u0438\u0434\u0443 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 \u0438 \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>GROUP BY<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e <code>species<\/code> \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e <code>num<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bbf\/c66\/0de\/bbfc660decbca4f528012f0182257e23.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bbf\/c66\/0de\/bbfc660decbca4f528012f0182257e23.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"49\" id=\"49\"><\/a><\/p>\n<h3>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/check_range.sql\" rel=\"noopener noreferrer nofollow\">src\/check_range.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH sized_penguins AS   (SELECT species,           CASE               WHEN body_mass_g BETWEEN 3500 AND 5000 THEN 'normal'               ELSE 'abnormal'           END AS SIZE    FROM penguins) SELECT species,        SIZE,        count(*) AS num FROM sized_penguins GROUP BY species,          SIZE ORDER BY species,          num; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/check_range.out\" rel=\"noopener noreferrer nofollow\">out\/check_range.out<\/a><\/p>\n<pre><code>|  species  |   size   | num | |-----------|----------|-----| | Adelie    | abnormal | 55  | | Adelie    | normal   | 97  | | Chinstrap | abnormal | 17  | | Chinstrap | normal   | 51  | | Gentoo    | abnormal | 62  | | Gentoo    | normal   | 62  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u0449\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (CTE) <code>sized_penguins<\/code>, \u043e\u043d\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0438\u0434 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0430\u0441\u0441\u044b \u0442\u0435\u043b\u0430; \u0435\u0441\u043b\u0438 \u043c\u0430\u0441\u0441\u0430 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 3500 \u0434\u043e 5000 \u0433, \u044d\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 <code>normal<\/code>, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; <code>abnormal<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0438\u0437 \u044d\u0442\u043e\u0439 CTE \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0432\u0438\u0434\u043e\u0432 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432, \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>SELECT<\/code> \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>COUNT(*)<\/code><\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0432\u0438\u0434\u0443 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>GROUP BY<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u0432\u0438\u0434\u0443 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>ORDER BY<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0411\u0414:<\/strong><\/p>\n<p>ER-\u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430\u043c\u0438 \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2f4\/882\/dab\/2f4882dabe944b0e27def05e8ca373e5.png\" alt=\"dios_6\" width=\"652\" height=\"312\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2f4\/882\/dab\/2f4882dabe944b0e27def05e8ca373e5.png\"\/><\/p>\n<div><figcaption>dios_6<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/73b\/0a0\/a23\/73b0a0a235aef58851cc52180696bfc3.png\" alt=\"dios_7\" width=\"502\" height=\"42\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/73b\/0a0\/a23\/73b0a0a235aef58851cc52180696bfc3.png\"\/><\/p>\n<div><figcaption>dios_7<\/figcaption><\/div>\n<\/figure>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/assay_staff.sql\" rel=\"noopener noreferrer nofollow\">src\/assay_staff.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM staff; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/assay_staff.out\" rel=\"noopener noreferrer nofollow\">out\/assay_staff.out<\/a><\/p>\n<pre><code>| ident | personal |  family   | dept | age | |-------|----------|-----------|------|-----| | 1     | Kartik   | Gupta     |      | 46  | | 2     | Divit    | Dhaliwal  | hist | 34  | | 3     | Indrans  | Sridhar   | mb   | 47  | | 4     | Pranay   | Khanna    | mb   | 51  | | 5     | Riaan    | Dua       |      | 23  | | 6     | Vedika   | Rout      | hist | 45  | | 7     | Abram    | Chokshi   | gen  | 23  | | 8     | Romil    | Kapoor    | hist | 38  | | 9     | Ishaan   | Ramaswamy | mb   | 35  | | 10    | Nitya    | Lal       | gen  | 52  | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/501\/182\/556\/5011825561f56f01107575ff139e6087.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/501\/182\/556\/5011825561f56f01107575ff139e6087.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"50\" id=\"50\"><\/a><\/p>\n<h3>\u0418\u0449\u0435\u043c \u043f\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/like_glob.sql\" rel=\"noopener noreferrer nofollow\">src\/like_glob.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT personal,        family FROM staff WHERE personal LIKE '%ya%'   OR family GLOB '*De*'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/like_glob.out\" rel=\"noopener noreferrer nofollow\">out\/like_glob.out<\/a><\/p>\n<pre><code>| personal | family | |----------|--------| | Nitya    | Lal    | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT personal, family<\/code> \u2014 \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>personal<\/code> \u0438 <code>family<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p><code>FROM staff<\/code> \u2014 \u043d\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p><code>'%ya%'<\/code> \u2014 \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>personal<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0443 <code>ya<\/code> (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>LIKE<\/code>) \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>family<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>De<\/code> (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>GLOB<\/code>)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/286\/222\/9ea\/2862229eaa76a2f31d43bbae7be6e349.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/286\/222\/9ea\/2862229eaa76a2f31d43bbae7be6e349.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"51\" id=\"51\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0442\u0440\u043e\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/union_all.sql\" rel=\"noopener noreferrer nofollow\">src\/union_all.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM   (SELECT *    FROM      (SELECT *       FROM experiment       ORDER BY started ASC       LIMIT 5)    UNION ALL SELECT *    FROM      (SELECT *       FROM experiment       ORDER BY started DESC       LIMIT 5)) ORDER BY started ASC ; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/union_all.out\" rel=\"noopener noreferrer nofollow\">out\/union_all.out<\/a><\/p>\n<pre><code>| ident |    kind     |  started   |   ended    | |-------|-------------|------------|------------| | 17    | trial       | 2023-01-29 | 2023-01-30 | | 35    | calibration | 2023-01-30 | 2023-01-30 | | 36    | trial       | 2023-02-02 | 2023-02-03 | | 25    | trial       | 2023-02-12 | 2023-02-14 | | 2     | calibration | 2023-02-14 | 2023-02-14 | | 40    | calibration | 2024-01-21 | 2024-01-21 | | 12    | trial       | 2024-01-26 | 2024-01-28 | | 44    | trial       | 2024-01-27 | 2024-01-29 | | 34    | trial       | 2024-02-01 | 2024-02-02 | | 14    | calibration | 2024-02-03 | 2024-02-03 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c 5 \u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0430\u0440\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>experiment<\/code>, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0434\u0430\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0430 (<code>started ASC<\/code>) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 <code>SELECT<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c 5 \u0441\u0430\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 <code>experiment<\/code>, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0430 (<code>started DESC<\/code>) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u044d\u0442\u0438 2 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>UNION ALL<\/code>, \u0442\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e 10 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 (5 \u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0430\u0440\u044b\u0445 \u0438 5 \u0441\u0430\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 (<code>SELECT *<\/code>) \u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0434\u0430\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0430 (<code>started ASC<\/code>) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e <code>ORDER BY<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9c3\/95e\/262\/9c395e2626b202d544f06fce32ade33f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c3\/95e\/262\/9c395e2626b202d544f06fce32ade33f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"52\" id=\"52\"><\/a><\/p>\n<h3>\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/intersect.sql\" rel=\"noopener noreferrer nofollow\">src\/intersect.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT personal,        family,        dept,        age FROM staff WHERE dept = 'mb' INTERSECT   SELECT personal,          family,          dept,          age   FROM staff WHERE age &lt; 50 ; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/intersect.out\" rel=\"noopener noreferrer nofollow\">out\/intersect.out<\/a><\/p>\n<pre><code>| personal |  family   | dept | age | |----------|-----------|------|-----| | Indrans  | Sridhar   | mb   | 47  | | Ishaan   | Ramaswamy | mb   | 35  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>INTERSECT<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0434\u0432\u0443\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>dept<\/code> \u0440\u0430\u0432\u043d\u043e <code>'mb'<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>age<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 50<\/p>\n<\/li>\n<li>\n<p>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>INTERSECT<\/code> \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u0449\u0438\u043c\u0438 \u0434\u043b\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043e\u0431\u043e\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>staff<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>dept<\/code> \u0440\u0430\u0432\u043d\u043e <code>'mb'<\/code> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>age<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 50<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b2e\/d3e\/261\/b2ed3e261195cb83b51e7a5098ddb03b.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b2e\/d3e\/261\/b2ed3e261195cb83b51e7a5098ddb03b.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"53\" id=\"53\"><\/a><\/p>\n<h3>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/except.sql\" rel=\"noopener noreferrer nofollow\">src\/except.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT personal,        family,        dept,        age FROM staff WHERE dept = 'mb' EXCEPT SELECT personal,        family,        dept,        age FROM staff WHERE age &lt; 50 ; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/except.out\" rel=\"noopener noreferrer nofollow\">out\/except.out<\/a><\/p>\n<pre><code>| personal | family | dept | age | |----------|--------|------|-----| | Pranay   | Khanna | mb   | 51  | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>SELECT<\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c 4 \u043f\u043e\u043b\u044f \u0438\u0437 <code>staff<\/code>: <code>personal<\/code>, <code>family<\/code>, <code>dept<\/code> \u0438 <code>age<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>WHERE<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>dept<\/code> \u0440\u0430\u0432\u043d\u043e <code>'mb'<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>EXCEPT<\/code> \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043b\u044e\u0431\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 <code>SELECT<\/code> \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 <code>staff<\/code>: <code>personal<\/code>, <code>family<\/code>, <code>dept<\/code> \u0438 <code>age<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>WHERE<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>age<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 50<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/088\/c76\/5d9\/088c765d93bd6f1a4d24fb514a5c5b0c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/088\/c76\/5d9\/088c765d93bd6f1a4d24fb514a5c5b0c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"54\" id=\"54\"><\/a><\/p>\n<h3>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/random_numbers.sql\" rel=\"noopener noreferrer nofollow\">src\/random_numbers.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH decorated AS   (SELECT random() AS rand,           personal || ' ' || family AS name    FROM staff) SELECT rand,        abs(rand) % 10 AS selector,        name FROM decorated WHERE selector &lt; 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/random_numbers.out\" rel=\"noopener noreferrer nofollow\">out\/random_numbers.out<\/a><\/p>\n<pre><code>|         rand         | selector |      name       | |----------------------|----------|-----------------| | 7176652035743196310  | 0        | Divit Dhaliwal  | | -2243654635505630380 | 2        | Indrans Sridhar | | -6940074802089166303 | 5        | Pranay Khanna   | | 8882650891091088193  | 9        | Riaan Dua       | | -45079732302991538   | 5        | Vedika Rout     | | -8973877087806386134 | 2        | Abram Chokshi   | | 3360598450426870356  | 9        | Romil Kapoor    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>decorated<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>random()<\/code><\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>personal<\/code> \u0438 <code>family<\/code> \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u0435\u043c <code>name<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>' '<\/code> \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>rand<\/code> \u0441 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0438 <code>name<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>personal<\/code> \u0438 <code>family<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p>\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>decorated<\/code>; \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>rand<\/code>, <code>name<\/code><\/p>\n<\/li>\n<li>\n<p><code>abs(rand) % 10<\/code> \u2014 \u044d\u0442\u043e \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>rand<\/code> \u043d\u0430 10<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u0433\u0434\u0435 <code>selector<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 5<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/570\/21c\/142\/57021c142951e7d1e167b7b0ca6a67e0.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/570\/21c\/142\/57021c142951e7d1e167b7b0ca6a67e0.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"55\" id=\"55\"><\/a><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/create_use_index.sql\" rel=\"noopener noreferrer nofollow\">src\/create_use_index.sql<\/a><\/p>\n<pre><code class=\"sql\">EXPLAIN query PLAN SELECT filename FROM plate WHERE filename like '%07%';  CREATE INDEX plate_file ON plate(filename);  EXPLAIN query PLAN SELECT filename FROM plate WHERE filename like '%07%'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/create_use_index.out\" rel=\"noopener noreferrer nofollow\">out\/create_use_index.out<\/a><\/p>\n<pre><code>QUERY PLAN `--SCAN plate USING COVERING INDEX sqlite_autoindex_plate_1 QUERY PLAN `--SCAN plate USING COVERING INDEX plate_file <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>filename<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>plate<\/code>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>filename<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0443 <code>07<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>plate_file<\/code> \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>filename<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>plate<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (<code>EXPLAIN query PLAN<\/code>)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/47b\/d2d\/0c5\/47bd2d0c58e0acd557a61da7c794f767.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47b\/d2d\/0c5\/47bd2d0c58e0acd557a61da7c794f767.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"56\" id=\"56\"><\/a><\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/generate_sequence.sql\" rel=\"noopener noreferrer nofollow\">src\/generate_sequence.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT value FROM generate_series(1, 5); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/generate_sequence.out\" rel=\"noopener noreferrer nofollow\">out\/generate_sequence.out<\/a><\/p>\n<pre><code>| value | |-------| | 1     | | 2     | | 3     | | 4     | | 5     | <\/code><\/pre>\n<ul>\n<li>\n<p><code>generate_series(1, 5)<\/code> \u2014 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u044f\u0434 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 1 \u0434\u043e 5<\/p>\n<\/li>\n<li>\n<p><code>SELECT value<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>value<\/code> \u0441\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 1 \u0434\u043e 5<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e80\/3d3\/b63\/e803d3b634de3fb8e868698a36796e7b.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e80\/3d3\/b63\/e803d3b634de3fb8e868698a36796e7b.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"57\" id=\"57\"><\/a><\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/data_range_sequence.sql\" rel=\"noopener noreferrer nofollow\">src\/data_range_sequence.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE temp (num integer NOT NULL);  INSERT INTO temp VALUES (1),        (5);  SELECT value FROM generate_series ((SELECT min(num)                        FROM TEMP),                       (SELECT max(num)                        FROM TEMP)); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/data_range_sequence.out\" rel=\"noopener noreferrer nofollow\">out\/data_range_sequence.out<\/a><\/p>\n<pre><code>| value | |-------| | 1     | | 2     | | 3     | | 4     | | 5     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>temp<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 1 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>num<\/code> \u0442\u0438\u043f\u0430 integer; \u044d\u0442\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 <code>temp<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 1 \u0438 5 \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>num<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>generate_series<\/code> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>num<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>temp<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f9e\/d53\/4ee\/f9ed534ee1296a876632c22c7039dea7.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f9e\/d53\/4ee\/f9ed534ee1296a876632c22c7039dea7.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"58\" id=\"58\"><\/a><\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u0430\u0442<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/date_sequence.sql\" rel=\"noopener noreferrer nofollow\">src\/date_sequence.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT date(               (SELECT julianday(min(started))                FROM experiment) + value) AS some_day FROM   (SELECT value    FROM generate_series(                           (SELECT 0),                           (SELECT count(*) - 1                            FROM experiment))) LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/date_sequence.out\" rel=\"noopener noreferrer nofollow\">out\/date_sequence.out<\/a><\/p>\n<pre><code>|  some_day  | |------------| | 2023-01-29 | | 2023-01-30 | | 2023-01-31 | | 2023-02-01 | | 2023-02-02 | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT julianday(min(started)) FROM experiment<\/code> \u2014 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>started<\/code> \u0438\u0437 <code>experiment<\/code>, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0435\u0451 \u0432 <code>Julian<\/code> \u0434\u0435\u043d\u044c (\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u0442\u044b) \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u044d\u0442\u043e\u0442 <code>Julian<\/code> \u0434\u0435\u043d\u044c<\/p>\n<\/li>\n<li>\n<p>\u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c <code>Julian<\/code> \u0434\u043d\u0435\u043c \u0438 \u043a\u0430\u0436\u0434\u044b\u043c <code>value<\/code> \u0438\u0437 <code>generate_series<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c <code>Julian<\/code> \u0434\u043d\u0435\u043c, \u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0434\u0430\u0442\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>date()<\/code><\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>LIMIT 5<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/124\/e83\/5e7\/124e835e7e117c4528c05f517fed1fad.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/124\/e83\/5e7\/124e835e7e117c4528c05f517fed1fad.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"59\" id=\"59\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430 \u0434\u0435\u043d\u044c, \u0431\u0435\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/experiments_per_day.sql\" rel=\"noopener noreferrer nofollow\">src\/experiments_per_day.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH -- complete sequence of days with 0 as placeholder for number of experiments           all_days AS (              SELECT DATE (                     (                        SELECT julianday (MIN(started))                          FROM experiment                     ) + VALUE                     ) AS some_day,                     0 AS zeroes                FROM (                        SELECT VALUE                          FROM generate_series (                               (                                  SELECT 0                               ),                               (                                  SELECT COUNT(*) - 1                                    FROM experiment                               )                               )                     )           ), -- sequence of actual days with actual number of experiments started           actual_days AS (              SELECT started,                     COUNT(started) AS num_exp                FROM experiment            GROUP BY started           ) -- combined by joining on day and taking actual number (if available) or zero    SELECT all_days.some_day AS DAY,           COALESCE(actual_days.num_exp, all_days.zeroes) AS num_exp      FROM all_days LEFT JOIN actual_days ON all_days.some_day = actual_days.started     LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/experiments_per_day.out\" rel=\"noopener noreferrer nofollow\">out\/experiments_per_day.out<\/a><\/p>\n<pre><code>|    day     | num_exp | |------------|---------| | 2023-01-29 | 1       | | 2023-01-30 | 1       | | 2023-01-31 | 0       | | 2023-02-01 | 0       | | 2023-02-02 | 1       | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0434\u043d\u0435\u0439 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043d\u0435\u0439 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u044d\u0442\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044f \u0438\u0445 \u043f\u043e \u0434\u043d\u044f\u043c \u0438 \u0431\u0435\u0440\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e (\u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e) \u0438\u043b\u0438 \u043d\u043e\u043b\u044c<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u0434\u043d\u0438 (<code>all_days.some_day<\/code>) \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 (<code>COALESCE(actual_days.num_exp, all_days.zeroes) AS num_exp<\/code>), \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>COALESCE<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e, \u0438\u043b\u0438 \u043d\u043e\u043b\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8aa\/0c1\/b38\/8aa0c1b3886be2e3dbe5628fc065cf64.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8aa\/0c1\/b38\/8aa0c1b3886be2e3dbe5628fc065cf64.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"60\" id=\"60\"><\/a><\/p>\n<h3>JOIN \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u0441 \u0441\u043e\u0431\u043e\u0439 \u0436\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/self_join.sql\" rel=\"noopener noreferrer nofollow\">src\/self_join.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH person AS (              SELECT ident,                     personal || ' ' || family AS name                FROM staff           )    SELECT LEFT.name,           RIGHT.name      FROM person AS LEFT JOIN person AS RIGHT     LIMIT 10; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/self_join.out\" rel=\"noopener noreferrer nofollow\">out\/self_join.out<\/a><\/p>\n<pre><code>|     name     |       name       | |--------------|------------------| | Kartik Gupta | Kartik Gupta     | | Kartik Gupta | Divit Dhaliwal   | | Kartik Gupta | Indrans Sridhar  | | Kartik Gupta | Pranay Khanna    | | Kartik Gupta | Riaan Dua        | | Kartik Gupta | Vedika Rout      | | Kartik Gupta | Abram Chokshi    | | Kartik Gupta | Romil Kapoor     | | Kartik Gupta | Ishaan Ramaswamy | | Kartik Gupta | Nitya Lal        | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u0449\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>person<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WITH<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>personal<\/code> \u0438 <code>family<\/code> \u0432 \u043e\u0434\u0438\u043d \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>name<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>SELECT<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 <code>person<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>name<\/code> \u0447\u0435\u0440\u0435\u0437 \u0430\u043b\u0438\u0430\u0441\u044b <code>left<\/code> \u0438 <code>right<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 <code>person<\/code> \u0441 \u0441\u043e\u0431\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>LEFT JOIN<\/code>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u043b\u0438\u0430\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>RIGHT<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 <a href=\"https:\/\/uproger.com\/gde-uchit-sql-besplatno-v-2024-godu\/\" rel=\"noopener noreferrer nofollow\">SQL<\/a>-\u043a\u043e\u0434, \u043e\u0434\u043d\u0430\u043a\u043e, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<pre><code class=\"sql\">     WITH person AS (              SELECT ident,                     personal || ' ' || family AS name                FROM staff           )    SELECT LEFT.name,           RIGHT.name      FROM person AS LEFT LEFT JOIN person AS RIGHT ON &lt; \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f >     LIMIT 10; <\/code><\/pre>\n<p>\u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (<code>ON<\/code>) \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/02c\/aa7\/b64\/02caa7b640893c0dce5524027d78b07d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/02c\/aa7\/b64\/02caa7b640893c0dce5524027d78b07d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"61\" id=\"61\"><\/a><\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/unique_pairs.sql\" rel=\"noopener noreferrer nofollow\">src\/unique_pairs.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH person AS (              SELECT ident,                     personal || ' ' || family AS name                FROM staff           )    SELECT LEFT.name,           RIGHT.name      FROM person AS LEFT JOIN person AS RIGHT ON LEFT.ident &lt; RIGHT.ident     WHERE LEFT.ident &lt;= 4       AND RIGHT.ident &lt;= 4; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/unique_pairs.out\" rel=\"noopener noreferrer nofollow\">out\/unique_pairs.out<\/a><\/p>\n<pre><code>|      name       |      name       | |-----------------|-----------------| | Kartik Gupta    | Divit Dhaliwal  | | Kartik Gupta    | Indrans Sridhar | | Kartik Gupta    | Pranay Khanna   | | Divit Dhaliwal  | Indrans Sridhar | | Divit Dhaliwal  | Pranay Khanna   | | Indrans Sridhar | Pranay Khanna   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>person<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0431\u043e\u0440\u0430 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 <code>person<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>left.name<\/code> \u0438 <code>right.name<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u044f (<code>JOIN<\/code>). \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0438\u044f\u043d\u0438\u0435 <code>person<\/code> \u0441 \u0441\u043e\u0431\u043e\u0439, \u043f\u0440\u0438\u0447\u0435\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043f\u0438\u044f <code>person<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u0435\u0432\u043e\u0439 \u0438 \u043f\u0440\u0430\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0421\u043b\u0438\u044f\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0447\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043b\u0435\u0432\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0441\u043f\u0440\u0430\u0432\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>WHERE<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>JOIN<\/code>-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0441\u043b\u0435\u0432\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u044b 4<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8b7\/7ce\/5df\/8b77ce5dffda26f052e656780469efa3.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8b7\/7ce\/5df\/8b77ce5dffda26f052e656780469efa3.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"62\" id=\"62\"><\/a><\/p>\n<h3>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u0430\u0440<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter_pairs.sql\" rel=\"noopener noreferrer nofollow\">src\/filter_pairs.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH person AS (              SELECT ident,                     personal || ' ' || family AS name                FROM staff           ),           together AS (              SELECT LEFT.staff AS left_staff,                     RIGHT.staff AS right_staff                FROM performed AS           LEFT JOIN performed AS RIGHT ON LEFT.experiment = RIGHT.experiment               WHERE left_staff &lt; right_staff           )    SELECT LEFT.name AS person_1,           RIGHT.name AS person_2      FROM person AS LEFT JOIN person AS     RIGHT JOIN together ON LEFT.ident = left_staff       AND RIGHT.ident = right_staff; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter_pairs.out\" rel=\"noopener noreferrer nofollow\">out\/filter_pairs.out<\/a><\/p>\n<pre><code>|    person_1     |     person_2     | |-----------------|------------------| | Kartik Gupta    | Vedika Rout      | | Pranay Khanna   | Vedika Rout      | | Indrans Sridhar | Romil Kapoor     | | Abram Chokshi   | Ishaan Ramaswamy | | Pranay Khanna   | Vedika Rout      | | Kartik Gupta    | Abram Chokshi    | | Abram Chokshi   | Romil Kapoor     | | Kartik Gupta    | Divit Dhaliwal   | | Divit Dhaliwal  | Abram Chokshi    | | Pranay Khanna   | Ishaan Ramaswamy | | Indrans Sridhar | Romil Kapoor     | | Kartik Gupta    | Ishaan Ramaswamy | | Kartik Gupta    | Nitya Lal        | | Kartik Gupta    | Abram Chokshi    | | Pranay Khanna   | Romil Kapoor     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0435 <code>person<\/code> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>staff<\/code>; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>personal ' ' family AS name<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>personal<\/code> \u0438 <code>family<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 <code>together<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>LEFT JOIN<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>performed<\/code> \u0441 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>experiment<\/code>. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u044b \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432, \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0432\u0448\u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438 \u0442\u043e\u043c \u0436\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0435, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 (<code>left_staff<\/code>) \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 (<code>right_staff<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 <code>SELECT<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>person<\/code> \u0438 <code>together<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432. \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0432\u0430 <code>LEFT JOIN<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c <code>person<\/code> \u0441 \u0441\u0430\u043c\u0438\u043c \u0441\u043e\u0431\u043e\u0439 \u0438 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 <code>together<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/216\/e6c\/56d\/216e6c56d64481736ed635875320814c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/216\/e6c\/56d\/216e6c56d64481736ed635875320814c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"63\" id=\"63\"><\/a><\/p>\n<h3>EXISTS<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/correlated_subquery.sql\" rel=\"noopener noreferrer nofollow\">src\/correlated_subquery.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT name,        building FROM department WHERE EXISTS     (SELECT 1      FROM staff      WHERE dept = department.ident ) ORDER BY name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/correlated_subquery.out\" rel=\"noopener noreferrer nofollow\">out\/correlated_subquery.out<\/a><\/p>\n<pre><code>|       name        |     building     | |-------------------|------------------| | Genetics          | Chesson          | | Histology         | Fashet Extension | | Molecular Biology | Chesson          | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>name<\/code> \u0438 <code>building<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code><\/p>\n<\/li>\n<li>\n<p><code>WHERE EXISTS (SELECT 1 FROM staff WHERE dept = department.ident )<\/code> \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>staff<\/code>, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>dept<\/code> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>ident<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code><\/p>\n<\/li>\n<li>\n<p><code>ORDER BY name<\/code> \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>name<\/code> \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b5c\/7de\/c1d\/b5c7dec1df78778e75fee1d79f1cddb2.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b5c\/7de\/c1d\/b5c7dec1df78778e75fee1d79f1cddb2.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"64\" id=\"64\"><\/a><\/p>\n<h3>NOT EXISTS \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/nonexistence.sql\" rel=\"noopener noreferrer nofollow\">src\/nonexistence.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT name,        building FROM department WHERE NOT EXISTS     (SELECT 1      FROM staff      WHERE dept = department.ident ) ORDER BY name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/nonexistence.out\" rel=\"noopener noreferrer nofollow\">out\/nonexistence.out<\/a><\/p>\n<pre><code>|     name      | building | |---------------|----------| | Endocrinology | TGVH     | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>name<\/code> \u0438 <code>building<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code><\/p>\n<\/li>\n<li>\n<p><code>WHERE NOT EXISTS<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 <code>department<\/code>, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p><code>SELECT 1 FROM staff WHERE dept = department.ident<\/code> \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>staff<\/code>, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043e\u0442\u0434\u0435\u043b\u043e\u043c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code><\/p>\n<\/li>\n<li>\n<p><code>ORDER BY name<\/code> \u2014 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 name<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0418\u0437\u0431\u0435\u0433\u0430\u043d\u0438\u0435 \u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/avoid_correlated_subqueries.sql\" rel=\"noopener noreferrer nofollow\">src\/avoid_correlated_subqueries.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT department.name AS name,                 department.building AS building FROM department JOIN staff ON department.ident = staff.dept ORDER BY name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/avoid_correlated_subqueries.out\" rel=\"noopener noreferrer nofollow\">out\/avoid_correlated_subqueries.out<\/a><\/p>\n<pre><code>|       name        |     building     | |-------------------|------------------| | Genetics          | Chesson          | | Histology         | Fashet Extension | | Molecular Biology | Chesson          | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT DISTINCT<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>name<\/code> \u0438 <code>building<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code><\/p>\n<\/li>\n<li>\n<p><code>JOIN staff ON department.ident = staff.dept<\/code> \u2014 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>department<\/code> \u0438 <code>staff<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>ident<\/code> \u0438\u0437 <code>department<\/code> \u0440\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <code>dept<\/code> \u0438\u0437 <code>staff<\/code><\/p>\n<\/li>\n<li>\n<p><code>ORDER BY name<\/code> \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>name<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6dc\/d14\/8f9\/6dcd148f90321f1f89ee43973967a809.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6dc\/d14\/8f9\/6dcd148f90321f1f89ee43973967a809.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"65\" id=\"65\"><\/a><\/p>\n<h3>\u041e\u043f\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/lead_lag.sql\" rel=\"noopener noreferrer nofollow\">src\/lead_lag.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH ym_num AS (              SELECT strftime ('%Y-%m', started) AS ym,                     COUNT(*) AS num                FROM experiment            GROUP BY ym           )    SELECT ym,           lag (num) OVER (            ORDER BY ym           ) AS prev_num,           num,           lead (num) OVER (            ORDER BY ym           ) AS next_num      FROM ym_num  ORDER BY ym; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/lead_lag.out\" rel=\"noopener noreferrer nofollow\">out\/lead_lag.out<\/a><\/p>\n<pre><code>|   ym    | prev_num | num | next_num | |---------|----------|-----|----------| | 2023-01 |          | 2   | 5        | | 2023-02 | 2        | 5   | 5        | | 2023-03 | 5        | 5   | 1        | | 2023-04 | 5        | 1   | 6        | | 2023-05 | 1        | 6   | 5        | | 2023-06 | 6        | 5   | 3        | | 2023-07 | 5        | 3   | 2        | | 2023-08 | 3        | 2   | 4        | | 2023-09 | 2        | 4   | 6        | | 2023-10 | 4        | 6   | 4        | | 2023-12 | 6        | 4   | 5        | | 2024-01 | 4        | 5   | 2        | | 2024-02 | 5        | 2   |          | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>ym_num<\/code> \u0438\u0437 2 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: <code>ym<\/code> (\u0433\u043e\u0434-\u043c\u0435\u0441\u044f\u0446 &#8216;YYYY-MM&#8217;) \u0438 <code>num<\/code> (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u0435\u0441\u044f\u0446\u0435)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c SQLite <code>strftime<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0433\u043e\u0434\u0430 \u0438 \u043c\u0435\u0441\u044f\u0446\u0430 \u0438\u0437 <code>started<\/code>, \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>GROUP BY<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 <code>ym_num<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u043e\u0434-\u043c\u0435\u0441\u044f\u0446 <code>ym<\/code>, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043c\u0435\u0441\u044f\u0446\u0435 <code>(lag)num<\/code>, \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 <code>num<\/code> \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043c\u0435\u0441\u044f\u0446\u0435 <code>(lead)num<\/code><\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>ym<\/code> (\u0433\u043e\u0434-\u043c\u0435\u0441\u044f\u0446)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/464\/937\/e30\/464937e30e857d38db3c28a793e9f47b.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/464\/937\/e30\/464937e30e857d38db3c28a793e9f47b.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"66\" id=\"66\"><\/a><\/p>\n<h3>\u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/window_functions.sql\" rel=\"noopener noreferrer nofollow\">src\/window_functions.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH ym_num AS (              SELECT strftime ('%Y-%m', started) AS ym,                     COUNT(*) AS num                FROM experiment            GROUP BY ym           )    SELECT ym,           num,           SUM(num) OVER (            ORDER BY ym           ) AS num_done,           CUME_DIST() OVER (            ORDER BY ym           ) AS progress      FROM ym_num  ORDER BY ym; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/window_functions.out\" rel=\"noopener noreferrer nofollow\">out\/window_functions.out<\/a><\/p>\n<pre><code>|   ym    | num | num_done |      progress      | |---------|-----|----------|--------------------| | 2023-01 | 2   | 2        | 0.0769230769230769 | | 2023-02 | 5   | 7        | 0.153846153846154  | | 2023-03 | 5   | 12       | 0.230769230769231  | | 2023-04 | 1   | 13       | 0.307692307692308  | | 2023-05 | 6   | 19       | 0.384615384615385  | | 2023-06 | 5   | 24       | 0.461538461538462  | | 2023-07 | 3   | 27       | 0.538461538461538  | | 2023-08 | 2   | 29       | 0.615384615384615  | | 2023-09 | 4   | 33       | 0.692307692307692  | | 2023-10 | 6   | 39       | 0.769230769230769  | | 2023-12 | 4   | 43       | 0.846153846153846  | | 2024-01 | 5   | 48       | 0.923076923076923  | | 2024-02 | 2   | 50       | 1.0                | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>ym_num<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442: <code>ym<\/code> \u2014 \u0433\u043e\u0434 \u0438 \u043c\u0435\u0441\u044f\u0446, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 <code>started<\/code> \u0432 <code>experiment<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>strftime('%Y-%m')<\/code>; <code>num<\/code> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 <code>experiment<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0433\u043e\u0434\u0430 \u0438 \u043c\u0435\u0441\u044f\u0446\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c <code>ym<\/code> \u0438 <code>num<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>ym_num<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c 2 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u0430: <code>num_done<\/code> \u2014 \u0441\u0443\u043c\u043c\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0433\u043e\u0434\u0430\u043c \u0438 \u043c\u0435\u0441\u044f\u0446\u0430\u043c (<code>sum(num) OVER (ORDER BY ym)<\/code>); <code>progress<\/code> \u2014 \u043a\u0443\u043c\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0433\u043e\u0434\u0430\u043c \u0438 \u043c\u0435\u0441\u044f\u0446\u0430\u043c (<code>cume_dist() OVER (ORDER BY ym)<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>ym<\/code> (\u0433\u043e\u0434 \u0438 \u043c\u0435\u0441\u044f\u0446)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435: \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0438\u0436\u0435<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/explain_window_function.sql\" rel=\"noopener noreferrer nofollow\">src\/explain_window_function.sql<\/a><\/p>\n<pre><code class=\"sql\">EXPLAIN query PLAN      WITH ym_num AS (              SELECT strftime ('%Y-%m', started) AS ym,                     COUNT(*) AS num                FROM experiment            GROUP BY ym           )    SELECT ym,           num,           SUM(num) OVER (            ORDER BY ym           ) AS num_done,           CUME_DIST() OVER (            ORDER BY ym           ) AS progress      FROM ym_num  ORDER BY ym; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/explain_window_function.out\" rel=\"noopener noreferrer nofollow\">out\/explain_window_function.out<\/a><\/p>\n<pre><code>QUERY PLAN |--CO-ROUTINE (subquery-3) |  |--CO-ROUTINE (subquery-4) |  |  |--CO-ROUTINE ym_num |  |  |  |--SCAN experiment |  |  |  `--USE TEMP B-TREE FOR GROUP BY |  |  |--SCAN ym_num |  |  `--USE TEMP B-TREE FOR ORDER BY |  `--SCAN (subquery-4) `--SCAN (subquery-3) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>ym_num<\/code> \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u043c\u0435\u0441\u044f\u0446\u0430\u043c, \u0433\u0434\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 <code>started<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 \u0433\u043e\u0434-\u043c\u0435\u0441\u044f\u0446 (<code>strftime('%Y-%m', started) AS ym<\/code>) \u0438 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (<code>count(*) AS num<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u043f\u043e\u043b\u044e <code>ym<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043b\u044f <code>ym<\/code> \u0438 <code>num<\/code> \u0438\u0437 <code>ym_num<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c 2 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044f: <code>num_done<\/code> \u0438 <code>progress<\/code>; <code>num_done<\/code> \u2014 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439\/\u043c\u0435\u0441, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0441\u044f\u0446\u0430; \u043f\u043e\u043b\u0435 <code>progress<\/code> \u2014 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u043e\u043c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 (<code>cume_dist()<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>ym<\/code> (\u0433\u043e\u0434-\u043c\u0435\u0441\u044f\u0446)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2eb\/206\/f3d\/2eb206f3d173bcba360b7a9447bf3bd4.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2eb\/206\/f3d\/2eb206f3d173bcba360b7a9447bf3bd4.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"67\" id=\"67\"><\/a><\/p>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c PARTITION BY \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/partition_window.sql\" rel=\"noopener noreferrer nofollow\">src\/partition_window.sql<\/a><\/p>\n<pre><code class=\"sql\">WITH y_m_num AS   (SELECT strftime('%Y', started) AS YEAR,           strftime('%m', started) AS MONTH,           count(*) AS num    FROM experiment    GROUP BY YEAR,             MONTH) SELECT YEAR,        MONTH,        num,        sum(num) OVER (PARTITION BY YEAR                       ORDER BY MONTH) AS num_done FROM y_m_num ORDER BY YEAR,          MONTH; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/partition_window.out\" rel=\"noopener noreferrer nofollow\">out\/partition_window.out<\/a><\/p>\n<pre><code>| year | month | num | num_done | |------|-------|-----|----------| | 2023 | 01    | 2   | 2        | | 2023 | 02    | 5   | 7        | | 2023 | 03    | 5   | 12       | | 2023 | 04    | 1   | 13       | | 2023 | 05    | 6   | 19       | | 2023 | 06    | 5   | 24       | | 2023 | 07    | 3   | 27       | | 2023 | 08    | 2   | 29       | | 2023 | 09    | 4   | 33       | | 2023 | 10    | 6   | 39       | | 2023 | 12    | 4   | 43       | | 2024 | 01    | 5   | 5        | | 2024 | 02    | 2   | 7        | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>y_m_num<\/code> \u0441 \u0442\u0440\u0435\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>YEAR,<\/code> <code>MONTH<\/code> \u0438 <code>num<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438 \u0438\u0437 <code>experiment<\/code>. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0433\u043e\u0434 \u0438 \u043c\u0435\u0441\u044f\u0446 \u0434\u0430\u0442\u044b \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>started<\/code> (\u0447\u0435\u0440\u0435\u0437 <code>strftime<\/code>), \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 (<code>count(*)<\/code>) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u043e\u0434\u0430 \u0438 \u043c\u0435\u0441\u044f\u0446\u0430, \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0433\u043e\u0434\u0443 \u0438 \u043c\u0435\u0441\u044f\u0446\u0443<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 <code>y_m_num<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>num_done<\/code> \u2014 \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>num<\/code> \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u043e\u0434\u0430 <code>sum(num) OVER (PARTITION BY YEAR ORDER BY MONTH)<\/code> \u2014 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>num<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0441\u044f\u0446\u0430 \u043f\u0440\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435 \u043f\u043e \u043c\u0435\u0441\u044f\u0446\u0430\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432 \u0438\u0442\u043e\u0433\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0433\u043e\u0434\u0443 \u0438 \u043c\u0435\u0441\u044f\u0446\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>ORDER BY YEAR, MONTH<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/464\/f03\/0fa\/464f030fa01b17eea058f2a24e0476d2.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/464\/f03\/0fa\/464f030fa01b17eea058f2a24e0476d2.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"68\" id=\"68\"><\/a><\/p>\n<h3>\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 blob<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/blob.sql\" rel=\"noopener noreferrer nofollow\">src\/blob.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE images (name text NOT NULL,                                content blob);  INSERT INTO images(name, content) VALUES (\"biohazard\", readfile(\"img\/biohazard.png\")),        (\"crush\", readfile(\"img\/crush.png\")),        (\"fire\", readfile(\"img\/fire.png\")),        (\"radioactive\", readfile(\"img\/radioactive.png\")),        (\"tripping\", readfile(\"img\/tripping.png\"));  SELECT name,        length(content) FROM images; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/blob.out\" rel=\"noopener noreferrer nofollow\">out\/blob.out<\/a><\/p>\n<pre><code>|    name     | length(content) | |-------------|-----------------| | biohazard   | 19629           | | crush       | 15967           | | fire        | 18699           | | radioactive | 16661           | | tripping    | 17208           | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>images<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>name<\/code> \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c; <code>content<\/code> \u2014 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (<code>blob<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c 5 \u043f\u0430\u0440 <code>name<\/code>&#8212;<code>blob<\/code> \u0432 <code>images<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>INSERT INTO<\/code><\/p>\n<\/li>\n<li>\n<p><code>readfile<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 <code>name<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043a \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 <code>blob<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 <code>images<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SELECT<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>name<\/code> \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 <code>content<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0411\u0414<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/lab_log_db.sh\" rel=\"noopener noreferrer nofollow\">src\/lab_log_db.sh<\/a><\/p>\n<pre><code>sqlite3 data\/lab_log.db <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/lab_log_schema.sql\" rel=\"noopener noreferrer nofollow\">src\/lab_log_schema.sql<\/a><\/p>\n<pre><code>.schema <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/lab_log_schema.out\" rel=\"noopener noreferrer nofollow\">out\/lab_log_schema.out<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE sqlite_sequence(name,                              seq);  CREATE TABLE person(ident integer PRIMARY KEY autoincrement,                                               details text NOT NULL);  CREATE TABLE machine(ident integer PRIMARY KEY autoincrement,                                                name text NOT NULL,                                                          details text NOT NULL);  CREATE TABLE usage(ident integer PRIMARY KEY autoincrement,                                              log text NOT NULL); <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>sqlite_sequence<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>name<\/code> \u0438 <code>seq<\/code> (\u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>AUTOINCREMENT<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>person<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>ident<\/code> (\u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c (<code>PRIMARY KEY<\/code>), \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f) \u0438 <code>details<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>NULL<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>machine<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>ident<\/code> (\u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c (<code>PRIMARY KEY<\/code>), \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f), <code>name<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>NULL<\/code>), <code>details<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>NULL<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>usage<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>ident<\/code> (\u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c (<code>PRIMARY KEY<\/code>), \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f) \u0438 <code>log<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>NULL<\/code>)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c78\/cb3\/c38\/c78cb3c38403aaeea1de5d203dbb2d8e.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c78\/cb3\/c38\/c78cb3c38403aaeea1de5d203dbb2d8e.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"69\" id=\"69\"><\/a><\/p>\n<h3>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 JSON<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_in_table.sql\" rel=\"noopener noreferrer nofollow\">src\/json_in_table.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM machine; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_in_table.out\" rel=\"noopener noreferrer nofollow\">out\/json_in_table.out<\/a><\/p>\n<pre><code>| ident |      name      |                         details                         | |-------|----------------|---------------------------------------------------------| | 1     | WY401          | {\"acquired\": \"2023-05-01\"}                              | | 2     | Inphormex      | {\"acquired\": \"2021-07-15\", \"refurbished\": \"2023-10-22\"} | | 3     | AutoPlate 9000 | {\"note\": \"needs software update\"}                       | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b7\/7e4\/45b\/7b77e445bba7d2948a7cf5a17d4a8532.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b7\/7e4\/45b\/7b77e445bba7d2948a7cf5a17d4a8532.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"70\" id=\"70\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 JSON<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_field.sql\" rel=\"noopener noreferrer nofollow\">src\/json_field.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT details->'$.acquired' AS single_arrow,                 details->>'$.acquired' AS double_arrow FROM machine; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_field.out\" rel=\"noopener noreferrer nofollow\">out\/json_field.out<\/a><\/p>\n<pre><code>| single_arrow | double_arrow | |--------------|--------------| | \"2023-05-01\" | 2023-05-01   | | \"2021-07-15\" | 2021-07-15   | |              |              | <\/code><\/pre>\n<ul>\n<li>\n<p><code>details->'$.acquired' AS single_arrow<\/code> \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>-><\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 JSON \u043f\u043e\u043b\u044f <code>acquired<\/code> \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>details<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <code>machine<\/code>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a <code>single_arrow<\/code><\/p>\n<\/li>\n<li>\n<p><code>details->>'$.acquired' AS double_arrow<\/code> \u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>->><\/code> \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f JSON \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438, \u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>-><\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 JSON \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435; \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 JSON \u043f\u043e\u043b\u044f <code>acquired<\/code> \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>details<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <code>machine<\/code>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a <code>double_arrow<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0b5\/0a5\/35b\/0b50a535b4d95d9483814bd656814e92.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0b5\/0a5\/35b\/0b50a535b4d95d9483814bd656814e92.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"71\" id=\"71\"><\/a><\/p>\n<h3>\u0414\u043e\u0441\u0442\u0443\u043f \u043a JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0443<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_array.sql\" rel=\"noopener noreferrer nofollow\">src\/json_array.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT ident,        json_array_length(log->'$') AS LENGTH,        log->'$[0]' AS FIRST FROM USAGE; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_array.out\" rel=\"noopener noreferrer nofollow\">out\/json_array.out<\/a><\/p>\n<pre><code>| ident | length |                            first                             | |-------|--------|--------------------------------------------------------------| | 1     | 4      | {\"machine\":\"Inphormex\",\"person\":[\"Gabrielle\",\"Dub\\u00e9\"]}   | | 2     | 5      | {\"machine\":\"Inphormex\",\"person\":[\"Marianne\",\"Richer\"]}       | | 3     | 2      | {\"machine\":\"sterilizer\",\"person\":[\"Josette\",\"Villeneuve\"]}   | | 4     | 1      | {\"machine\":\"sterilizer\",\"person\":[\"Maude\",\"Goulet\"]}         | | 5     | 2      | {\"machine\":\"AutoPlate 9000\",\"person\":[\"Brigitte\",\"Michaud\"]} | | 6     | 1      | {\"machine\":\"sterilizer\",\"person\":[\"Marianne\",\"Richer\"]}      | | 7     | 3      | {\"machine\":\"WY401\",\"person\":[\"Maude\",\"Goulet\"]}              | | 8     | 1      | {\"machine\":\"AutoPlate 9000\"}                                 | <\/code><\/pre>\n<ul>\n<li>\n<p><code>json_array_length(log->'$') AS LENGTH<\/code> \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>log<\/code>; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>-><\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438 <code>json_array_length<\/code> \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>LENGTH<\/code><\/p>\n<\/li>\n<li>\n<p><code>log->'$[0]' AS FIRST<\/code> \u2014 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>log<\/code>; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>-><\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443, \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>FIRST<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f42\/7d7\/2a5\/f427d72a57d028bf35fc3fbf0b46ec2c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f42\/7d7\/2a5\/f427d72a57d028bf35fc3fbf0b46ec2c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"72\" id=\"72\"><\/a><\/p>\n<h3>\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 JSON<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_unpack.sql\" rel=\"noopener noreferrer nofollow\">src\/json_unpack.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT ident,        json_each.key AS KEY,        json_each.value AS value FROM USAGE,      json_each(usage.log) LIMIT 10; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_unpack.out\" rel=\"noopener noreferrer nofollow\">out\/json_unpack.out<\/a><\/p>\n<pre><code>| ident | key |                            value                             | |-------|-----|--------------------------------------------------------------| | 1     | 0   | {\"machine\":\"Inphormex\",\"person\":[\"Gabrielle\",\"Dub\\u00e9\"]}   | | 1     | 1   | {\"machine\":\"Inphormex\",\"person\":[\"Gabrielle\",\"Dub\\u00e9\"]}   | | 1     | 2   | {\"machine\":\"WY401\",\"person\":[\"Gabrielle\",\"Dub\\u00e9\"]}       | | 1     | 3   | {\"machine\":\"Inphormex\",\"person\":[\"Gabrielle\",\"Dub\\u00e9\"]}   | | 2     | 0   | {\"machine\":\"Inphormex\",\"person\":[\"Marianne\",\"Richer\"]}       | | 2     | 1   | {\"machine\":\"AutoPlate 9000\",\"person\":[\"Marianne\",\"Richer\"]}  | | 2     | 2   | {\"machine\":\"sterilizer\",\"person\":[\"Marianne\",\"Richer\"]}      | | 2     | 3   | {\"machine\":\"AutoPlate 9000\",\"person\":[\"Monique\",\"Marcotte\"]} | | 2     | 4   | {\"machine\":\"sterilizer\",\"person\":[\"Marianne\",\"Richer\"]}      | | 3     | 0   | {\"machine\":\"sterilizer\",\"person\":[\"Josette\",\"Villeneuve\"]}   | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT ident, json_each.key AS KEY, json_each.value AS value<\/code> \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>usage<\/code> \u0438 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>json_each<\/code>; \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043b\u044e\u0447 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>log<\/code><\/p>\n<\/li>\n<li>\n<p><code>FROM usage, json_each(usage.log)<\/code> \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438; <code>usage<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 FROM, \u0430 <code>json_each<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 <code>log<\/code>, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/p>\n<\/li>\n<li>\n<p><code>LIMIT 10<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 10 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5e5\/ab6\/1a1\/5e5ab61a1ccfde95b823ec5ebbf63ab8.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e5\/ab6\/1a1\/5e5ab61a1ccfde95b823ec5ebbf63ab8.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"73\" id=\"73\"><\/a><\/p>\n<h3>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_array_last.sql\" rel=\"noopener noreferrer nofollow\">src\/json_array_last.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT ident,        log->'$[#-1].machine' AS FINAL FROM USAGE LIMIT 5; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_array_last.out\" rel=\"noopener noreferrer nofollow\">out\/json_array_last.out<\/a><\/p>\n<pre><code>| ident |    final     | |-------|--------------| | 1     | \"Inphormex\"  | | 2     | \"sterilizer\" | | 3     | \"Inphormex\"  | | 4     | \"sterilizer\" | | 5     | \"sterilizer\" | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT ident, log->'$[#-1].machine' AS FINAL<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c 2 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0438\u0437 <code>machine<\/code>; <code>ident<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c, \u0430 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>log<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a: <\/p>\n<ul>\n<li>\n<p><code>log->'$[#-1].machine<\/code> \u2014 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>log<\/code> (<code>-><\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a JSON-\u043f\u043e\u043b\u044e \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>log<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>$[#-1]<\/code> \u2014 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <code>log<\/code><\/p>\n<\/li>\n<li>\n<p><code>.machine<\/code> \u2014 \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>machine<\/code> \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/817\/d17\/d37\/817d17d372042964743ceb442253475b.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/817\/d17\/d37\/817d17d372042964743ceb442253475b.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"74\" id=\"74\"><\/a><\/p>\n<h3>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c JSON<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/json_modify.sql\" rel=\"noopener noreferrer nofollow\">src\/json_modify.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT ident,        name,        json_set(details, '$.sold', json_quote('2024-01-25')) AS updated FROM machine; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/json_modify.out\" rel=\"noopener noreferrer nofollow\">out\/json_modify.out<\/a><\/p>\n<pre><code>| ident |      name      |                           updated                            | |-------|----------------|--------------------------------------------------------------| | 1     | WY401          | {\"acquired\":\"2023-05-01\",\"sold\":\"2024-01-25\"}                | | 2     | Inphormex      | {\"acquired\":\"2021-07-15\",\"refurbished\":\"2023-10-22\",\"sold\":\" | |       |                | 2024-01-25\"}                                                 | | 3     | AutoPlate 9000 | {\"note\":\"needs software update\",\"sold\":\"2024-01-25\"}         | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT ident, name, ... FROM machine;<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>ident<\/code> \u0438 <code>name<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>machine<\/code><\/p>\n<\/li>\n<li>\n<p><code>json_set(details, '$.sold', json_quote('2024-01-25')) AS updated<\/code> \u2014 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>json_set<\/code> \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c JSON-\u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>details<\/code>; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\/\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>sold<\/code> \u0432 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>details<\/code>, \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044f \u0435\u043c\u0443 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>json_quote<\/code>; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a <code>updated<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 penguins:<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/count_penguins.sql\" rel=\"noopener noreferrer nofollow\">src\/count_penguins.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        count(*) AS num FROM penguins GROUP BY species; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/count_penguins.out\" rel=\"noopener noreferrer nofollow\">out\/count_penguins.out<\/a><\/p>\n<pre><code>|  species  | num | |-----------|-----| | Adelie    | 152 | | Chinstrap | 68  | | Gentoo    | 124 | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/720\/fed\/401\/720fed401ab6bf987baca6c137ed4bbe.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/720\/fed\/401\/720fed401ab6bf987baca6c137ed4bbe.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"75\" id=\"75\"><\/a><\/p>\n<h3>Immediate If \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/make_active.sql\" rel=\"noopener noreferrer nofollow\">src\/make_active.sql<\/a><\/p>\n<pre><code class=\"sql\">ALTER TABLE penguins ADD active integer NOT NULL DEFAULT 1;  UPDATE penguins SET active = IIF(species = 'Adelie', 0, 1); <\/code><\/pre>\n<ul>\n<li>\n<p>\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>penguins<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>active<\/code> \u0442\u0438\u043f\u0430 <code>integer<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>NULL<\/code>, \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 <code>active<\/code> \u0432 <code>penguins<\/code>; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>active<\/code> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 0, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>species<\/code> \u0440\u0430\u0432\u043d\u043e <code>'Adelie'<\/code>, \u0438\u043d\u0430\u0447\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 1<\/p>\n<\/li>\n<li>\n<p>\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>IIF<\/code> (Immediate If) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (1 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0443\u0441\u043b\u043e\u0432\u0438\u0435, 2 &#8212; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u0438 3 &#8212; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043b\u043e\u0436\u043d\u043e)<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/active_penguins.sql\" rel=\"noopener noreferrer nofollow\">src\/active_penguins.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        count(*) AS num FROM penguins WHERE active GROUP BY species; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/active_penguins.out\" rel=\"noopener noreferrer nofollow\">out\/active_penguins.out<\/a><\/p>\n<pre><code>|  species  | num | |-----------|-----| | Chinstrap | 68  | | Gentoo    | 124 | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2a3\/596\/57d\/2a359657d67d6b8fb3d9dabec3ab2948.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a3\/596\/57d\/2a359657d67d6b8fb3d9dabec3ab2948.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"76\" id=\"76\"><\/a><\/p>\n<h3>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 VIEW \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/views.sql\" rel=\"noopener noreferrer nofollow\">src\/views.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE VIEW IF NOT EXISTS active_penguins (species, island, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, sex) AS SELECT species,        island,        bill_length_mm,        bill_depth_mm,        flipper_length_mm,        body_mass_g,        sex FROM penguins WHERE active;  SELECT species,        count(*) AS num FROM active_penguins GROUP BY species; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/views.out\" rel=\"noopener noreferrer nofollow\">out\/views.out<\/a><\/p>\n<pre><code>|  species  | num | |-----------|-----| | Chinstrap | 68  | | Gentoo    | 124 | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (<code>VIEW<\/code>) \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>active_penguins<\/code>, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>island<\/code>, <code>bill_length_mm<\/code>, <code>bill_depth_mm<\/code>, <code>flipper_length_mm<\/code>, <code>body_mass_g<\/code>, \u0438 <code>sex<\/code>; \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0438\u0437 <code>penguins<\/code>, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 (<code>WHERE active<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>active_penguins<\/code>: \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0438\u0434 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u0430 (<code>species<\/code>) \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 (<code>num<\/code>), \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c, \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 <code>active_penguins<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043e \u0447\u0430\u0441\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b:<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/all_jobs.sql\" rel=\"noopener noreferrer nofollow\">src\/all_jobs.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (name text NOT NULL,                   billable real NOT NULL);  INSERT INTO job VALUES ('calibrate', 1.5),        ('clean', 0.5);  SELECT * FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/all_jobs.out\" rel=\"noopener noreferrer nofollow\">out\/all_jobs.out<\/a><\/p>\n<pre><code>|   name    | billable | |-----------|----------| | calibrate | 1.5      | | clean     | 0.5      | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f40\/64d\/ad7\/f4064dad7bf7b56e622eb728fe3cb75d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f40\/64d\/ad7\/f4064dad7bf7b56e622eb728fe3cb75d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"77\" id=\"77\"><\/a><\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 CHECK<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/all_jobs_check.sql\" rel=\"noopener noreferrer nofollow\">src\/all_jobs_check.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (name text NOT NULL,                   billable real NOT NULL, CHECK (billable > 0.0));  INSERT INTO job VALUES ('calibrate', 1.5);  INSERT INTO job VALUES ('reset', -0.5);  SELECT * FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/all_jobs_check.out\" rel=\"noopener noreferrer nofollow\">out\/all_jobs_check.out<\/a><\/p>\n<pre><code>Runtime error near line 9: CHECK constraint failed: billable > 0.0 (19) |   name    | billable | |-----------|----------| | calibrate | 1.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 2 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c\u0438: <code>name<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445) \u0438 <code>billable<\/code> (\u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445)<\/p>\n<\/li>\n<li>\n<p>\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 (<code>CHECK<\/code>) \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>billable<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c 0.0<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 <code>job<\/code> \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>'calibrate'<\/code> \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>name<\/code> \u0438 1.5 \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>billable<\/code> \u2014 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0434 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>CHECK<\/code> \u044d\u0442\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>'reset'<\/code> \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>name<\/code> \u0438 -0.5 \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>billable<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a \u043a\u0430\u043a -0.5 \u043c\u0435\u043d\u044c\u0448\u0435 \u043b\u0438\u0431\u043e \u0440\u0430\u0432\u043d\u043e 0.0, \u0442\u043e \u044d\u0442\u043e \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>CHECK<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>ACID<\/strong><\/p>\n<p>ACID \u2014 \u044d\u0442\u043e \u0430\u043a\u0440\u043e\u043d\u0438\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043e\u043a, \u0441\u0431\u043e\u0435\u0432 \u043f\u0438\u0442\u0430\u043d\u0438\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u0435\u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439:<\/p>\n<ol>\n<li>\n<p><strong>\u0410\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c (Atomicity)<\/strong>: \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0439, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438\u043b\u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0432\u043e\u043e\u0431\u0449\u0435. \u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u0442\u043e \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c (Consistency)<\/strong>: \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c (Isolation)<\/strong>: \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435. \u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0442\u0430\u043a, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0434\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c \u0434\u043e \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u043b\u0433\u043e\u0432\u0435\u0447\u043d\u043e\u0441\u0442\u044c (Durability)<\/strong>: \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u043c\u0438 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 SSD.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ab8\/aaf\/c3c\/ab8aafc3c64584ca94a76190de237259.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ab8\/aaf\/c3c\/ab8aafc3c64584ca94a76190de237259.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"78\" id=\"78\"><\/a><\/p>\n<h3>TRANSACTION \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/transaction.sql\" rel=\"noopener noreferrer nofollow\">src\/transaction.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (name text NOT NULL,                   billable real NOT NULL, CHECK (billable > 0.0));  INSERT INTO job VALUES ('calibrate', 1.5); BEGIN TRANSACTION;  INSERT INTO job VALUES ('clean', 0.5); ROLLBACK;  SELECT * FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/transaction.out\" rel=\"noopener noreferrer nofollow\">out\/transaction.out<\/a><\/p>\n<pre><code>|   name    | billable | |-----------|----------| | calibrate | 1.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 2 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c\u0438: <\/p>\n<ul>\n<li>\n<p><code>name<\/code> \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430<\/p>\n<\/li>\n<li>\n<p><code>billable<\/code> \u0441 \u0442\u0438\u043f\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 <code>real<\/code> (\u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e) \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c <code>CHECK (billable > 0.0)<\/code>, \u0447\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>billable<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 0.0<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>job<\/code> \u0437\u0430\u043f\u0438\u0441\u044c: <code>('calibrate', 1.5)<\/code><\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code>: <code>('clean', 0.5)<\/code><\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f <code>'clean', 0.5<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b7d\/9dc\/d3a\/b7d9dcd3a002b6c1e0191dedd4b5acf7.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b7d\/9dc\/d3a\/b7d9dcd3a002b6c1e0191dedd4b5acf7.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"79\" id=\"79\"><\/a><\/p>\n<h3>ROLLBACK \u0432 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/rollback_constraint.sql\" rel=\"noopener noreferrer nofollow\">src\/rollback_constraint.sql<\/a><\/p>\n<pre><code class=\"sql\">   CREATE TABLE job (           name text NOT NULL,           billable real NOT NULL,           CHECK (billable > 0.0) ON CONFLICT ROLLBACK           );     INSERT INTO job    VALUES ('calibrate', 1.5);     INSERT INTO job    VALUES ('clean', 0.5),           ('reset', -0.5);     SELECT *      FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/rollback_constraint.out\" rel=\"noopener noreferrer nofollow\">out\/rollback_constraint.out<\/a><\/p>\n<pre><code>Runtime error near line 11: CHECK constraint failed: billable > 0.0 (19) |   name    | billable | |-----------|----------| | calibrate | 1.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>job<\/code> \u0438 2 \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c <code>name<\/code> \u0438 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c <code>billable<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>billable<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 0 (<code>CHECK (billable > 0.0)<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>job<\/code> \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>calibrate<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>billable<\/code> 1.5<\/p>\n<\/li>\n<li>\n<p>\u0432\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>clean<\/code> \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>billable<\/code> \u0440\u0430\u0432\u043d\u043e\u0435 0.5<\/p>\n<\/li>\n<li>\n<p>\u0442\u0440\u0435\u0442\u044c\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>reset<\/code> \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>billable<\/code> \u0440\u0430\u0432\u043d\u043e\u0435 -0.5 \u2014 \u0442\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 <code>CHECK (billable > 0.0)<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a99\/ae2\/2ee\/a99ae22ee25293d15e59fb70106a724d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a99\/ae2\/2ee\/a99ae22ee25293d15e59fb70106a724d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"80\" id=\"80\"><\/a><\/p>\n<h3>\u041e\u0442\u043a\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ROLLBACK<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/rollback_statement.sql\" rel=\"noopener noreferrer nofollow\">src\/rollback_statement.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE job (name text NOT NULL,                             billable real NOT NULL,                                           CHECK (billable > 0.0)); INSERT OR ROLLBACK INTO job VALUES ('calibrate', 1.5);  INSERT OR ROLLBACK INTO job VALUES ('clean', 0.5),        ('reset', -0.5);         SELECT * FROM job; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/rollback_statement.out\" rel=\"noopener noreferrer nofollow\">out\/rollback_statement.out<\/a><\/p>\n<pre><code>Runtime error near line 11: CHECK constraint failed: billable > 0.0 (19) |   name    | billable | |-----------|----------| | calibrate | 1.5      | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 2 \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <\/p>\n<ul>\n<li>\n<p>\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c <code>name<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u043c <code>billable<\/code> \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c <code>CHECK (billable > 0.0)<\/code> \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>job<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>INSERT OR ROLLBACK<\/code>, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0443 \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>calibrate<\/code> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>billable<\/code> \u0440\u0430\u0432\u043d\u044b\u043c 1.5<\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0449\u0451 2 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>INSERT OR ROLLBACK<\/code>: <code>clean<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 0.5 \u0434\u043b\u044f <code>billable<\/code>, <code>reset<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c -0.5 <code>billable<\/code> (\u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e <code>CHECK<\/code>)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0ff\/0d8\/6fe\/0ff0d86fe36c5e2417debd6710889b67.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ff\/0d8\/6fe\/0ff0d86fe36c5e2417debd6710889b67.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"81\" id=\"81\"><\/a><\/p>\n<h3>\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/upsert.sql\" rel=\"noopener noreferrer nofollow\">src\/upsert.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE jobs_done (person text UNIQUE,                                     num integer DEFAULT 0);  INSERT INTO jobs_done VALUES(\"zia\", 1);  .print \"after first\" SELECT * FROM jobs_done;  .print INSERT INTO jobs_done VALUES(\"zia\", 1);  .print \"after failed\" SELECT * FROM jobs_done;  INSERT INTO jobs_done VALUES(\"zia\", 1) ON conflict(person) DO UPDATE SET num = num + 1;  .print \"\\nafter upsert\" SELECT * FROM jobs_done; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/upsert.out\" rel=\"noopener noreferrer nofollow\">out\/upsert.out<\/a><\/p>\n<pre><code>after first | person | num | |--------|-----| | zia    | 1   |  Runtime error near line 14: UNIQUE constraint failed: jobs_done.person (19) after failed | person | num | |--------|-----| | zia    | 1   |  after upsert | person | num | |--------|-----| | zia    | 2   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>jobs_done<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>person<\/code> (\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438) \u0438 <code>num<\/code> (\u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0432\u0435\u043d 0)<\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>jobs_done<\/code> \u0437\u0430\u043f\u0438\u0441\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>\"zia\"<\/code> \u0438 \u0447\u0438\u0441\u043b\u043e\u043c 1<\/p>\n<\/li>\n<li>\n<p>\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c <code>\"zia\"<\/code> \u0438 \u0447\u0438\u0441\u043b\u043e\u043c 1 \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>SELECT<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c <code>\"zia\"<\/code> \u0438 \u0447\u0438\u0441\u043b\u043e\u043c 1 \u043d\u043e \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0430 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>person<\/code>, \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>num<\/code>, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432 \u0435\u0433\u043e \u043d\u0430 1<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eb5\/091\/30f\/eb509130f6b67cbc751f21a9bac8c61c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb5\/091\/30f\/eb509130f6b67cbc751f21a9bac8c61c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"82\" id=\"82\"><\/a><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/trigger_setup.sql\" rel=\"noopener noreferrer nofollow\">src\/trigger_setup.sql<\/a><\/p>\n<pre><code class=\"sql\">-- Track hours of lab work. CREATE TABLE job (person text NOT NULL,                               reported real NOT NULL CHECK (reported >= 0.0));  -- Explicitly store per-person total rather than using sum(). CREATE TABLE total (person text UNIQUE NOT NULL,                                        hours real);  -- Initialize totals. INSERT INTO total VALUES (\"gene\", 0.0),        (\"august\", 0.0);  -- Define a trigger. CREATE TRIGGER total_trigger BEFORE INSERT ON job BEGIN -- Check that the person exists.  SELECT CASE            WHEN NOT EXISTS                   (SELECT 1                    FROM total                    WHERE person = new.person) THEN raise                   (ROLLBACK, 'Unknown person ')        END; -- Update their total hours (or fail if non-negative constraint violated).  UPDATE total SET hours = hours + new.reported WHERE total.person = new.person; END; <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>person<\/code> \u0438 <code>reported<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>total<\/code> \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 <code>person<\/code> \u0438 <code>hours<\/code><\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>gene<\/code> \u0438 <code>august<\/code> \u0432 0.0<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0440\u0438\u0433\u0433\u0435\u0440 <code>total_trigger<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439 \u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>job<\/code>. \u042d\u0442\u043e\u0442 \u0442\u0440\u0438\u0433\u0433\u0435\u0440: <\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>total<\/code>, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 <a href=\"https:\/\/uproger.com\/sql-dorozhnaya-karta-2024-goda\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/a> <code>job<\/code><\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>total<\/code> \u043f\u0443\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u043e\u0432 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>job<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/trigger_successful.sql\" rel=\"noopener noreferrer nofollow\">src\/trigger_successful.sql<\/a><\/p>\n<pre><code class=\"sql\">INSERT INTO job VALUES ('gene', 1.5),        ('august', 0.5),        ('gene', 1.0); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/trigger_successful.out\" rel=\"noopener noreferrer nofollow\">out\/trigger_successful.out<\/a><\/p>\n<pre><code>| person | reported | |--------|----------| | gene   | 1.5      | | august | 0.5      | | gene   | 1.0      |  | person | hours | |--------|-------| | gene   | 2.5   | | august | 0.5   | <\/code><\/pre>\n<p><strong>\u0421\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/trigger_firing.sql\" rel=\"noopener noreferrer nofollow\">src\/trigger_firing.sql<\/a><\/p>\n<pre><code class=\"sql\">INSERT INTO job VALUES ('gene', 1.0),        ('august', -1.0) ; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/trigger_firing.out\" rel=\"noopener noreferrer nofollow\">out\/trigger_firing.out<\/a><\/p>\n<pre><code>Runtime error near line 6: CHECK constraint failed: reported >= 0.0 (19)  | person | hours | |--------|-------| | gene   | 0.0   | | august | 0.0   | <\/code><\/pre>\n<p><strong>\u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/lineage_setup.sql\" rel=\"noopener noreferrer nofollow\">src\/lineage_setup.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TABLE lineage (parent text NOT NULL,                       child text NOT NULL); INSERT INTO lineage VALUES ('Arturo', 'Clemente'),        ('Dar\u00edo', 'Clemente'),        ('Clemente', 'Homero'),        ('Clemente', 'Ivonne'),        ('Ivonne', 'Lourdes'),        ('Soledad', 'Lourdes'),        ('Lourdes', 'Santiago'); <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/represent_graph.sql\" rel=\"noopener noreferrer nofollow\">src\/represent_graph.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM lineage; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/represent_graph.out\" rel=\"noopener noreferrer nofollow\">out\/represent_graph.out<\/a><\/p>\n<pre><code>|  parent  |  child   | |----------|----------| | Arturo   | Clemente | | Dar\u00edo    | Clemente | | Clemente | Homero   | | Clemente | Ivonne   | | Ivonne   | Lourdes  | | Soledad  | Lourdes  | | Lourdes  | Santiago | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c88\/9c9\/b23\/c889c9b238401f21e35ca7e1846d84cf.png\" alt=\"dios_8\" width=\"402\" height=\"312\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c88\/9c9\/b23\/c889c9b238401f21e35ca7e1846d84cf.png\"\/><\/p>\n<div><figcaption>dios_8<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/892\/593\/8bf\/8925938bf300e1b018d8613a7e274bf7.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/892\/593\/8bf\/8925938bf300e1b018d8613a7e274bf7.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"83\" id=\"83\"><\/a><\/p>\n<h3>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/recursive_lineage.sql\" rel=\"noopener noreferrer nofollow\">src\/recursive_lineage.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH RECURSIVE descendent AS (              SELECT 'Clemente' AS person,                     0 AS generations           UNION ALL              SELECT lineage.child AS person,                     descendent.generations + 1 AS generations                FROM descendent                JOIN lineage ON descendent.person = lineage.parent           )    SELECT person,           generations      FROM descendent; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/recursive_lineage.out\" rel=\"noopener noreferrer nofollow\">out\/recursive_lineage.out<\/a><\/p>\n<pre><code>|  person  | generations | |----------|-------------| | Clemente | 0           | | Homero   | 1           | | Ivonne   | 1           | | Lourdes  | 2           | | Santiago | 3           | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u0442\u0435\u0440\u043c\u0438\u043d <code>descendent<\/code> (\u043f\u043e\u0442\u043e\u043c\u043e\u043a) \u043a\u0430\u043a \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 \u043e\u0431\u0449\u0435\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438, \u0433\u0434\u0435 <code>'Clemente'<\/code> &#8212; \u044d\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f, \u0430 0 &#8212; \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0441\u0430\u043c\u0438\u043c \u0441\u043e\u0431\u043e\u0439 (\u0441 <code>descendent<\/code>) \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>lineage<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>lineage<\/code>, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0439 \u043d\u0430 1 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>SELECT<\/code> \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>person<\/code> \u0438 <code>generations<\/code> \u0438\u0437 <code>descendent<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u043e\u0432<\/strong><\/p>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/contact_person.sql\" rel=\"noopener noreferrer nofollow\">src\/contact_person.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM person; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/contact_person.out\" rel=\"noopener noreferrer nofollow\">out\/contact_person.out<\/a><\/p>\n<pre><code>| ident |         name          | |-------|-----------------------| | 1     | Juana Baeza           | | 2     | Agust\u00edn Rodr\u00edquez     | | 3     | Ariadna Caraballo     | | 4     | Micaela Laboy         | | 5     | Ver\u00f3nica Altamirano   | | 6     | Reina Rivero          | | 7     | Elias Merino          | | 8     | Minerva Guerrero      | | 9     | Mauro Balderas        | | 10    | Pilar Alarc\u00f3n         | | 11    | Daniela Men\u00e9ndez      | | 12    | Marco Antonio Barrera | | 13    | Cristal Soliz         | | 14    | Bernardo Narv\u00e1ez      | | 15    | \u00d3scar Barrios         | <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/contact_contacts.sql\" rel=\"noopener noreferrer nofollow\">src\/contact_contacts.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT * FROM contact; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/contact_contacts.out\" rel=\"noopener noreferrer nofollow\">out\/contact_contacts.out<\/a><\/p>\n<pre><code>|       left        |         right         | |-------------------|-----------------------| | Agust\u00edn Rodr\u00edquez | Ariadna Caraballo     | | Agust\u00edn Rodr\u00edquez | Ver\u00f3nica Altamirano   | | Juana Baeza       | Ver\u00f3nica Altamirano   | | Juana Baeza       | Micaela Laboy         | | Pilar Alarc\u00f3n     | Reina Rivero          | | Cristal Soliz     | Marco Antonio Barrera | | Cristal Soliz     | Daniela Men\u00e9ndez      | | Daniela Men\u00e9ndez  | Marco Antonio Barrera | <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cef\/74e\/aa1\/cef74eaa1ec68e157f7da64cef6d83ec.png\" alt=\"dios_9\" width=\"540\" height=\"290\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cef\/74e\/aa1\/cef74eaa1ec68e157f7da64cef6d83ec.png\"\/><\/p>\n<div><figcaption>dios_9<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9de\/a53\/d2c\/9dea53d2c4a08b9581f0ee8cd70af467.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9de\/a53\/d2c\/9dea53d2c4a08b9581f0ee8cd70af467.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"84\" id=\"84\"><\/a><\/p>\n<h3>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 bi_contact<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/bidirectional.sql\" rel=\"noopener noreferrer nofollow\">src\/bidirectional.sql<\/a><\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE bi_contact (LEFT text, RIGHT text);     INSERT INTO bi_contact    SELECT LEFT,           RIGHT      FROM contact UNION ALL    SELECT RIGHT,           LEFT      FROM contact; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/bidirectional.out\" rel=\"noopener noreferrer nofollow\">out\/bidirectional.out<\/a><\/p>\n<pre><code>| original_count | |----------------| | 8              |  | num_contact | |-------------| | 16          | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>bi_contact<\/code> \u0441 2 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>LEFT<\/code> \u0438 <code>RIGHT<\/code>, \u043e\u0431\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>bi_contact<\/code> \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>SELECT<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>UNION ALL<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 2 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>SELECT<\/code> \u0432 \u043e\u0434\u0438\u043d \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445; \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>LEFT<\/code> \u0438 <code>RIGHT<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>contact<\/code> \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>bi_contact<\/code>. \u041f\u0435\u0440\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0440\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>LEFT<\/code> \u0438 <code>RIGHT<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>contact<\/code>, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0440\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>RIGHT<\/code> \u0438 <code>LEFT<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>contact<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u043e\u0431\u0449\u0435\u043c, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>bi_contact<\/code> \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>LEFT<\/code> \u0438 <code>RIGHT<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>contact<\/code> \u0438 \u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u0451\u0440\u043d\u0443\u0442\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3d2\/bf9\/1e0\/3d2bf91e02cb71905ecf572fba6d9bf8.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d2\/bf9\/1e0\/3d2bf91e02cb71905ecf572fba6d9bf8.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"85\" id=\"85\"><\/a><\/p>\n<h3>\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0433\u0440\u0443\u043f\u043f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/update_group_ids.sql\" rel=\"noopener noreferrer nofollow\">src\/update_group_ids.sql<\/a><\/p>\n<pre><code class=\"sql\">   SELECT left.name AS left_name,           left.ident AS left_ident,           right.name AS right_name,           right.ident AS right_ident,           min(left.ident, right.ident) AS new_ident      FROM (           person AS LEFT JOIN bi_contact ON left.name = bi_contact.left           )      JOIN person AS RIGHT ON bi_contact.right = right.name; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/update_group_ids.out\" rel=\"noopener noreferrer nofollow\">out\/update_group_ids.out<\/a><\/p>\n<pre><code>|       left_name       | left_ident |      right_name       | right_ident | new_ident | |-----------------------|------------|-----------------------|-------------|-----------| | Juana Baeza           | 1          | Micaela Laboy         | 4           | 1         | | Juana Baeza           | 1          | Ver\u00f3nica Altamirano   | 5           | 1         | | Agust\u00edn Rodr\u00edquez     | 2          | Ariadna Caraballo     | 3           | 2         | | Agust\u00edn Rodr\u00edquez     | 2          | Ver\u00f3nica Altamirano   | 5           | 2         | | Ariadna Caraballo     | 3          | Agust\u00edn Rodr\u00edquez     | 2           | 2         | | Micaela Laboy         | 4          | Juana Baeza           | 1           | 1         | | Ver\u00f3nica Altamirano   | 5          | Agust\u00edn Rodr\u00edquez     | 2           | 2         | | Ver\u00f3nica Altamirano   | 5          | Juana Baeza           | 1           | 1         | | Reina Rivero          | 6          | Pilar Alarc\u00f3n         | 10          | 6         | | Pilar Alarc\u00f3n         | 10         | Reina Rivero          | 6           | 6         | | Daniela Men\u00e9ndez      | 11         | Cristal Soliz         | 13          | 11        | | Daniela Men\u00e9ndez      | 11         | Marco Antonio Barrera | 12          | 11        | | Marco Antonio Barrera | 12         | Cristal Soliz         | 13          | 12        | | Marco Antonio Barrera | 12         | Daniela Men\u00e9ndez      | 11          | 11        | | Cristal Soliz         | 13         | Daniela Men\u00e9ndez      | 11          | 11        | | Cristal Soliz         | 13         | Marco Antonio Barrera | 12          | 12        | <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/618\/37c\/c19\/61837cc19e3af26f4cb016b02d3fe8d9.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/618\/37c\/c19\/61837cc19e3af26f4cb016b02d3fe8d9.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"86\" id=\"86\"><\/a><\/p>\n<h3>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/recursive_labeling.sql\" rel=\"noopener noreferrer nofollow\">src\/recursive_labeling.sql<\/a><\/p>\n<pre><code class=\"sql\">     WITH recursive labeled AS (              SELECT person.NAME AS NAME,                     person.ident AS label                FROM person               UNION -- not 'union all'              SELECT person.NAME AS NAME,                     labeled.label AS label                FROM (                     person                JOIN bi_contact ON person.NAME = bi_contact.LEFT                     )                JOIN labeled ON bi_contact.RIGHT = labeled.NAME               WHERE labeled.label &lt; person.ident           )    SELECT NAME,           min(label) AS group_id      FROM labeled  GROUP BY NAME  ORDER BY label,           NAME; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/recursive_labeling.out\" rel=\"noopener noreferrer nofollow\">out\/recursive_labeling.out<\/a><\/p>\n<pre><code>|         name          | group_id | |-----------------------|----------| | Agust\u00edn Rodr\u00edquez     | 1        | | Ariadna Caraballo     | 1        | | Juana Baeza           | 1        | | Micaela Laboy         | 1        | | Ver\u00f3nica Altamirano   | 1        | | Pilar Alarc\u00f3n         | 6        | | Reina Rivero          | 6        | | Elias Merino          | 7        | | Minerva Guerrero      | 8        | | Mauro Balderas        | 9        | | Cristal Soliz         | 11       | | Daniela Men\u00e9ndez      | 11       | | Marco Antonio Barrera | 11       | | Bernardo Narv\u00e1ez      | 14       | | \u00d3scar Barrios         | 15       | <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>labeled<\/code> \u2014 \u043e\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u0430 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b person,<\/p>\n<ul>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>UNION<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>person<\/code> \u0438 <code>bi_contact<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>name<\/code> \u0438 <code>left<\/code> \u0432 <code>bi_contact<\/code> \u0438 \u0438\u043c\u0435\u043d\u0430 \u0438 \u043c\u0435\u0442\u043a\u0438 \u0438\u0437 <code>person<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438 \u0438\u0437 <code>labeled<\/code><\/p>\n<\/li>\n<li>\n<p><code>WHERE<\/code> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0447\u0442\u043e \u043c\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 <code>person<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u0438\u0437 <code>labeled<\/code> \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0435\u0442\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043c\u0435\u043d\u0438 \u043a\u0430\u043a <code>group_id<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>min()<\/code><\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0438\u043c\u0435\u043d\u0430\u043c \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u043c\u0435\u0442\u043a\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e \u0438\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<li>\n<p>attention: \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0443\u0442 <code>UNION ALL<\/code>, \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/79d\/b77\/883\/79db77883008dbd48683a3c3c69ae252.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/79d\/b77\/883\/79db77883008dbd48683a3c3c69ae252.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"87\" id=\"87\"><\/a><\/p>\n<h3>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 SQL \u0432 Python \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 sqlite3<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/basic_python_query.py\" rel=\"noopener noreferrer nofollow\">src\/basic_python_query.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  connection = sqlite3.connect(\"db\/penguins.db\") cursor = connection.execute(\"SELECT count(*) FROM penguins;\") rows = cursor.fetchall() print(rows) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/basic_python_query.out\" rel=\"noopener noreferrer nofollow\">out\/basic_python_query.out<\/a><\/p>\n<pre><code>[(344,)] <\/code><\/pre>\n<ul>\n<li>\n<p>\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043a\u0443 <code>sqlite3<\/code> (\u043a \u0441\u043b\u043e\u0432\u0443, \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a) \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SQLite<\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>\"db\/penguins.db\"<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>sqlite3.connect()<\/code>. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>cursor<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><code>select count(*) from penguins;<\/code> \u2014 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p><code>fetchall()<\/code> \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>rows<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a2f\/54a\/d84\/a2f54ad84b670cdadf4aa16915f56e6a.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a2f\/54a\/d84\/a2f54ad84b670cdadf4aa16915f56e6a.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"88\" id=\"88\"><\/a><\/p>\n<h3>\u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/incremental_fetch.py\" rel=\"noopener noreferrer nofollow\">src\/incremental_fetch.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  connection = sqlite3.connect(\"db\/penguins.db\") cursor = connection.cursor() cursor = cursor.execute(\"SELECT species, island FROM penguins LIMIT 5;\") while row := cursor.fetchone():     print(row) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/incremental_fetch.out\" rel=\"noopener noreferrer nofollow\">out\/incremental_fetch.out<\/a><\/p>\n<pre><code>('Adelie', 'Torgersen') ('Adelie', 'Torgersen') ('Adelie', 'Torgersen') ('Adelie', 'Torgersen') ('Adelie', 'Torgersen') <\/code><\/pre>\n<ul>\n<li>\n<p>\u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0438\u043c\u0441\u044f \u043a \u0411\u0414 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>sqlite3.connect(\"db\/penguins.db\")<\/code><\/p>\n<\/li>\n<li>\n<p><code>connection.cursor()<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>cursor<\/code>, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><code>select species, island from penguins limit 5;<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>penguins<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>species<\/code> \u0438 <code>island<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>row<\/code> \u0438\u0437 <code>cursor.fetchone()<\/code> \u043d\u0435\u043f\u0443\u0441\u0442\u0430\u044f, \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u043c \u0435\u0451 (\u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>row<\/code> \u0438 \u0442\u0443\u0442 \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0451 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>:=<\/code> )<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ae6\/596\/feb\/ae6596feb985e156c8700a46ecbe451e.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ae6\/596\/feb\/ae6596feb985e156c8700a46ecbe451e.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"89\" id=\"89\"><\/a><\/p>\n<h3>\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CREATE, INSERT, DELETE \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sqlite3<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/insert_delete.py\" rel=\"noopener noreferrer nofollow\">src\/insert_delete.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  connection = sqlite3.connect(\":memory:\") cursor = connection.cursor() cursor.execute(\"CREATE TABLE example(num integer);\")  cursor.execute(\"INSERT INTO example VALUES (10),(20);\") print(\"after insertion\", cursor.execute(\"SELECT * FROM example;\").fetchall())  cursor.execute(\"DELETE FROM example WHERE num &lt; 15;\") print(\"after deletion\", cursor.execute(\"SELECT * FROM example;\").fetchall()) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/insert_delete.out\" rel=\"noopener noreferrer nofollow\">out\/insert_delete.out<\/a><\/p>\n<pre><code>after insertion [(10,), (20,)] after deletion [(20,)] <\/code><\/pre>\n<ul>\n<li>\n<p><code>connection = sqlite3.connect(\":memory:\")<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 SQLite, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><code>cursor = connection.cursor()<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u0443\u0440\u0441\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p><code>cursor.execute(\"CREATE TABLE example(num integer);\")<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>example<\/code> \u0438 \u043e\u0434\u043d\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c <code>num<\/code> \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/p>\n<\/li>\n<li>\n<p><code>cursor.execute(\"INSERT INTO example VALUES (10),(20);\")<\/code> \u2014 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c 2 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 <code>example<\/code> \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 10 \u0438 20 \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>num<\/code><\/p>\n<\/li>\n<li>\n<p><code>print(\"after insertion\", cursor.execute(\"SELECT * FROM example;\").fetchall())<\/code> \u2014 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0441\u0442\u0440\u043e\u043a; \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>SELECT<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>.fetchall()<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p><code>cursor.execute(\"DELETE FROM example WHERE num &lt; 15;\")<\/code> \u2014 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>num<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 15<\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u043f\u043e\u0441\u043b\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a; \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>SELECT<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>.fetchall()<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/385\/5c2\/c6c\/3855c2c6cf07788203d672e49aebc76c.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/385\/5c2\/c6c\/3855c2c6cf07788203d672e49aebc76c.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"90\" id=\"90\"><\/a><\/p>\n<h3>\u0418\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/interpolate.py\" rel=\"noopener noreferrer nofollow\">src\/interpolate.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  connection = sqlite3.connect(\":memory:\") cursor = connection.cursor() cursor.execute(\"CREATE TABLE example(num integer);\")  cursor.executemany(\"insert into example values (?);\", [(10,), (20,)]) print(\"after insertion\", cursor.execute(\"SELECT * FROM example;\").fetchall()) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/interpolate.out\" rel=\"noopener noreferrer nofollow\">out\/interpolate.out<\/a><\/p>\n<pre><code>after insertion [(10,), (20,)] <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8f5\/2fd\/8c0\/8f52fd8c008187cecf0f2a0dd825fcd4.png\" alt=\"XKCD Exploits of a Mom\" width=\"666\" height=\"205\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f5\/2fd\/8c0\/8f52fd8c008187cecf0f2a0dd825fcd4.png\"\/><\/p>\n<div><figcaption>XKCD Exploits of a Mom<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p><code>connection = sqlite3.connect(\":memory:\")<\/code> \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414 SQLite \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><code>cursor = connection.cursor()<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u0443\u0440\u0441\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p><code>cursor.execute(\"create table example(num integer);\")<\/code> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>example<\/code> \u0441 \u043e\u0434\u043d\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c <code>num<\/code> \u0442\u0438\u043f\u0430 integer<\/p>\n<\/li>\n<li>\n<p><code>cursor.executemany(\"insert into example values (?);\", [(10,), (20,)])<\/code> \u2014 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 10 \u0438 20 \u0432 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>num<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/659\/325\/e3b\/659325e3b5f626a56a7bf900e51dbe8f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/659\/325\/e3b\/659325e3b5f626a56a7bf900e51dbe8f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"91\" id=\"91\"><\/a><\/p>\n<h3>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 Python<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/script_execution.py\" rel=\"noopener noreferrer nofollow\">src\/script_execution.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  SETUP = \"\"\"\\ DROP TABLE IF EXISTS example; CREATE TABLE example(num integer); INSERT INTO example VALUES (10),        (20); \"\"\"  connection = sqlite3.connect(\":memory:\") cursor = connection.cursor() cursor.executescript(SETUP) print(\"after insertion\", cursor.execute(\"SELECT * FROM example;\").fetchall()) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/script_execution.out\" rel=\"noopener noreferrer nofollow\">out\/script_execution.out<\/a><\/p>\n<pre><code>after insertion [(10,), (20,)] <\/code><\/pre>\n<ul>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>example<\/code>, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>example<\/code> \u0441 \u043e\u0434\u043d\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c <code>num<\/code> \u0442\u0438\u043f\u0430 integer<\/p>\n<\/li>\n<li>\n<p>\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c 2 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>example<\/code> \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 10 \u0438 20<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>SETUP<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 <code>executescript()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c <code>after insertion<\/code> \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>execute()<\/code> \u0438 <code>fetchall()<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/423\/b91\/9ab\/423b919ab4a67d09abb30d48f98fcc36.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/423\/b91\/9ab\/423b919ab4a67d09abb30d48f98fcc36.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"92\" id=\"92\"><\/a><\/p>\n<h3>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f SQLite \u0432 Python<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/exceptions.py\" rel=\"noopener noreferrer nofollow\">src\/exceptions.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  SETUP = \"\"\"\\ CREATE TABLE example(num integer check(num > 0));  INSERT INTO example VALUES (10);  INSERT INTO example VALUES (-1);  INSERT INTO example VALUES (20); \"\"\"  connection = sqlite3.connect(\":memory:\") cursor = connection.cursor() try:     cursor.executescript(SETUP) except sqlite3.Error as exc:     print(f\"SQLite exception: {exc}\") print(\"after execution\", cursor.execute(\"SELECT * FROM example;\").fetchall()) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/exceptions.out\" rel=\"noopener noreferrer nofollow\">out\/exceptions.out<\/a><\/p>\n<pre><code>SQLite exception: CHECK constraint failed: num > 0 after execution [(10,)] <\/code><\/pre>\n<ul>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>sqlite3.connect(\":memory:\")<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u0443\u0440\u0441\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>example<\/code> \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u0435 3 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>executescript()<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u0431\u043b\u043e\u043a\u0435 <code>try-except<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>sqlite3.Error<\/code>, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>fetchall()<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a39\/ad6\/7d4\/a39ad67d401499426308b5bc032e8617.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a39\/ad6\/7d4\/a39ad67d401499426308b5bc032e8617.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"93\" id=\"93\"><\/a><\/p>\n<h3>Python \u0438 SQLite, \u0435\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/embedded_python.py\" rel=\"noopener noreferrer nofollow\">src\/embedded_python.py<\/a><\/p>\n<pre><code class=\"python\">import sqlite3  SETUP = \"\"\"\\ CREATE TABLE example(num integer); INSERT INTO example VALUES (-10),        (10),        (20),        (30); \"\"\"  def clip(value):     if value &lt; 0:         return 0     if value > 20:         return 20     return value  connection = sqlite3.connect(\":memory:\") connection.create_function(\"clip\", 1, clip) cursor = connection.cursor() cursor.executescript(SETUP) for row in cursor.execute(\"SELECT num, clip(num) FROM example;\").fetchall():     print(row) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/embedded_python.out\" rel=\"noopener noreferrer nofollow\">out\/embedded_python.out<\/a><\/p>\n<pre><code>(-10, 0) (10, 10) (20, 20) (30, 20) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0411\u0414 SQLite \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 <code>example<\/code>, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0435\u0451 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 (-10, 10, 20, 30)<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>clip<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 0 \u0438 20, \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 0, \u0435\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 0, \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 20, \u0435\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 20<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 <code>num<\/code> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>example<\/code> \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>clip<\/code> \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8ba\/6d4\/cff\/8ba6d4cff2817f9b8d4f20d1ec470a8d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ba\/6d4\/cff\/8ba6d4cff2817f9b8d4f20d1ec470a8d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"94\" id=\"94\"><\/a><\/p>\n<h3>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u0442\u043e\u0439 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/dates_times.py\" rel=\"noopener noreferrer nofollow\">src\/dates_times.py<\/a><\/p>\n<pre><code class=\"python\">from datetime import date import sqlite3  # Convert date to ISO-formatted string when writing to database def _adapt_date_iso(val):     return val.isoformat()  sqlite3.register_adapter(date, _adapt_date_iso)  # Convert ISO-formatted string to date when reading from database def _convert_date(val):     return date.fromisoformat(val.decode())  sqlite3.register_converter(\"date\", _convert_date)  SETUP = \"\"\"\\ CREATE TABLE events(happened date NOT NULL,                     description text NOT NULL); \"\"\"  connection = sqlite3.connect(\":memory:\", detect_types=sqlite3.PARSE_DECLTYPES) cursor = connection.cursor() cursor.execute(SETUP)  cursor.executemany(     \"insert into events values (?, ?);\",     [(date(2024, 1, 10), \"started tutorial\"), (date(2024, 1, 29), \"finished tutorial\")], )  for row in cursor.execute(\"SELECT * FROM EVENTS;\").fetchall():     print(row) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/dates_times.out\" rel=\"noopener noreferrer nofollow\">out\/dates_times.out<\/a><\/p>\n<pre><code>(datetime.date(2024, 1, 10), 'started tutorial') (datetime.date(2024, 1, 29), 'finished tutorial') <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>_adapt_date_iso(val)<\/code> \u2014 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0430\u0442\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>ISO<\/code><\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>_convert_date(val)<\/code> \u2014 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>ISO<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>date<\/code><\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 SQLite, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>SETUP<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 SQL-\u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>events<\/code> \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438: <code>happened<\/code> \u0442\u0438\u043f\u0430 <code>date<\/code> \u0438 <code>description<\/code> \u0442\u0438\u043f\u0430 <code>text<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>cursor.executemany<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>events<\/code> \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f 2 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0442\u0438\u043f\u0430 <code>date<\/code> \u0438 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>select * from events<\/code> \u0438 <code>cursor.execute<\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>events<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/456\/b21\/05f\/456b2105f0f458ef73080bd27c5b1c43.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/456\/b21\/05f\/456b2105f0f458ef73080bd27c5b1c43.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"95\" id=\"95\"><\/a><\/p>\n<h3>SQL \u0432 Jupyter Notebooks<\/h3>\n<pre><code class=\"python\">pip install jupysql <\/code><\/pre>\n<pre><code class=\"python\">%load_ext sql <\/code><\/pre>\n<pre><code class=\"python\">%sql sqlite:\/\/\/data\/penguins.db <\/code><\/pre>\n<pre><code class=\"python\">Connecting to 'sqlite:\/\/\/data\/penguins.db' <\/code><\/pre>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414: <\/p>\n<ul>\n<li>\n<p><code>sqlite:\/\/<\/code> \u2014 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0441 2 \u0441\u043b\u044d\u0448\u0430\u043c\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435<\/p>\n<\/li>\n<li>\n<p><code>\/data\/penguins.db<\/code> \u2014 1 \u0441\u043b\u044d\u0448 \u0441\u043f\u0435\u0440\u0435\u0434\u0438, \u044d\u0442\u043e \u043f\u0443\u0442\u044c \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0411\u0414<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>1 \u0437\u043d\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 <code>%sql<\/code> \u2014 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>2 \u0437\u043d\u0430\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 <code>%%sql<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043e\u0434\u0438\u043d SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"sql\">%%sql SELECT species,        count(*) AS num FROM penguins GROUP BY species; <\/code><\/pre>\n<pre><code class=\"python\">Running query in 'sqlite:\/\/\/data\/penguins.db' <\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>species<\/p>\n<\/th>\n<th>\n<p>num<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Adelie<\/p>\n<\/td>\n<td>\n<p align=\"left\">152<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Chinstrap<\/p>\n<\/td>\n<td>\n<p align=\"left\">68<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Gentoo<\/p>\n<\/td>\n<td>\n<p align=\"left\">124<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5a1\/fc8\/3df\/5a1fc83dfbaf13a34ed686f9e0c12cc0.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a1\/fc8\/3df\/5a1fc83dfbaf13a34ed686f9e0c12cc0.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"96\" id=\"96\"><\/a><\/p>\n<h3>Pandas \u0438 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/install_pandas.sh\" rel=\"noopener noreferrer nofollow\">src\/install_pandas.sh<\/a><\/p>\n<pre><code>pip install pandas <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/select_pandas.py\" rel=\"noopener noreferrer nofollow\">src\/select_pandas.py<\/a><\/p>\n<pre><code class=\"python\">import pandas as pd import sqlite3  connection = sqlite3.connect(\"db\/penguins.db\") query = \"SELECT species, count(*) AS num FROM penguins GROUP BY species;\" df = pd.read_sql(query, connection) print(df) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/select_pandas.out\" rel=\"noopener noreferrer nofollow\">out\/select_pandas.out<\/a><\/p>\n<pre><code>species  num 0     Adelie  152 1  Chinstrap   68 2     Gentoo  124 <\/code><\/pre>\n<ul>\n<li>\n<p><code>select species, count(*) as num from penguins group by species;<\/code> \u2014 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0438\u0437 <code>penguins<\/code> \u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u0432\u0438\u0434\u0430\u043c<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0430 <code>read_sql<\/code> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>pandas<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u0445 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>DataFrame<\/code> (df)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d16\/0c7\/d02\/d160c7d02c27107f6a7909684b3278fa.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d16\/0c7\/d02\/d160c7d02c27107f6a7909684b3278fa.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"97\" id=\"97\"><\/a><\/p>\n<h3>Polars \u0438 SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/install_polars.sh\" rel=\"noopener noreferrer nofollow\">src\/install_polars.sh<\/a><\/p>\n<pre><code>pip install polars pyarrow adbc-driver-sqlite <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/select_polars.py\" rel=\"noopener noreferrer nofollow\">src\/select_polars.py<\/a><\/p>\n<pre><code class=\"python\">import polars as pl  query = \"SELECT species, count(*) AS num FROM penguins GROUP BY species;\" uri = \"sqlite:\/\/\/db\/penguins.db\" df = pl.read_database_uri(query, uri, engine=\"adbc\") print(df) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/select_polars.out\" rel=\"noopener noreferrer nofollow\">out\/select_polars.out<\/a><\/p>\n<pre><code>shape: (3, 2) \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 species   \u2506 num \u2502 \u2502 ---       \u2506 --- \u2502 \u2502 str       \u2506 i64 \u2502 \u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2561 \u2502 Adelie    \u2506 152 \u2502 \u2502 Chinstrap \u2506 68  \u2502 \u2502 Gentoo    \u2506 124 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2518 <\/code><\/pre>\n<ul>\n<li>\n<p>\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Polars &#8212; \u043e\u043d\u0430 \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 pandas, \u043d\u043e \u0441 \u0444\u043e\u043a\u0443\u0441\u043e\u043c \u043d\u0430 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>species<\/code> \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u043f\u0438\u043d\u0433\u0432\u0438\u043d\u043e\u0432 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>penguins<\/code>; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <code>species<\/code><\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 SQLite \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>uri<\/code><\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>pl.read_database_uri<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>query<\/code> \u043a \u0411\u0414, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 <code>uri<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u0432\u0438\u0436\u043e\u043a <code>adbc<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/143\/007\/26e\/14300726ed60e53a137a65078bb3e8d9.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/143\/007\/26e\/14300726ed60e53a137a65078bb3e8d9.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"98\" id=\"98\"><\/a><\/p>\n<h3>ORM<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/orm.py\" rel=\"noopener noreferrer nofollow\">src\/orm.py<\/a><\/p>\n<pre><code class=\"python\">from sqlmodel import Field, Session, SQLModel, create_engine, select  class Department(SQLModel, table=True):     ident: str = Field(default=None, primary_key=True)     name: str     building: str  engine = create_engine(\"sqlite:\/\/\/db\/assays.db\") with Session(engine) as session:     statement = select(Department)     for result in session.exec(statement).all():         print(result) <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/orm.out\" rel=\"noopener noreferrer nofollow\">out\/orm.out<\/a><\/p>\n<pre><code class=\"python\">building='Chesson' name='Genetics' ident='gen' building='Fashet Extension' name='Histology' ident='hist' building='Chesson' name='Molecular Biology' ident='mb' building='TGVH' name='Endocrinology' ident='end' <\/code><\/pre>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 <code>Department<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u043e\u0432; \u043a\u0430\u0436\u0434\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>engine<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a SQLite \u0411\u0414, \u0433\u0434\u0435 <code>assays.db<\/code> &#8212; \u044d\u0442\u043e \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0411\u0414<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0451\u043c <code>Session<\/code> \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <code>engine<\/code><\/p>\n<\/li>\n<li>\n<p>\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>select(Department)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e <code>Department<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0411\u0414 \u0447\u0435\u0440\u0435\u0437 <code>session.exec(statement).all()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f67\/bdf\/8d3\/f67bdf8d30e39388a1c9dca8d10e872d.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f67\/bdf\/8d3\/f67bdf8d30e39388a1c9dca8d10e872d.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"99\" id=\"99\"><\/a><\/p>\n<h3>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 ORM<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/orm_relation.py\" rel=\"noopener noreferrer nofollow\">src\/orm_relation.py<\/a><\/p>\n<pre><code class=\"python\">class Staff(SQLModel, table=True):     ident: str = Field(default=None, primary_key=True)     personal: str     family: str     dept: Optional[str] = Field(default=None, foreign_key=\"department.ident\")     age: int  engine = create_engine(\"sqlite:\/\/\/db\/assays.db\") SQLModel.metadata.create_all(engine) with Session(engine) as session:     statement = select(Department, Staff).where(Staff.dept == Department.ident)     for dept, staff in session.exec(statement):         print(f\"{dept.name}: {staff.personal} {staff.family}\") <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/orm_relation.out\" rel=\"noopener noreferrer nofollow\">out\/orm_relation.out<\/a><\/p>\n<pre><code>Histology: Divit Dhaliwal Molecular Biology: Indrans Sridhar Molecular Biology: Pranay Khanna Histology: Vedika Rout Genetics: Abram Chokshi Histology: Romil Kapoor Molecular Biology: Ishaan Ramaswamy Genetics: Nitya Lal <\/code><\/pre>\n<ul>\n<li>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Staff<\/code>; \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 SQLModel, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a \u0441\u0445\u0435\u043c\u0443 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414. \u0423\u043a\u0430\u0437\u0430\u043d\u0438\u0435 <code>table=True<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 SQLModel \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430. \u0423 <code>Staff<\/code> \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 :<\/p>\n<ul>\n<li>\n<p><code>ident<\/code> &#8212; \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>None<\/code> \u0438 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 (<code>primary_key=True<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>personal<\/code> &#8212; \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435<\/p>\n<\/li>\n<li>\n<p><code>family<\/code> &#8212; \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435<\/p>\n<\/li>\n<li>\n<p><code>dept<\/code> &#8212; \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435; \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>None<\/code> \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 (<code>foreign_key=\"department.ident\"<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>age<\/code> &#8212; \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <code>Staff<\/code>, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0432\u0438\u0436\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414 SQLite \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>create_engine<\/code> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 SQLAlchemy<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>create_all<\/code> \u0443 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 SQLModel, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SQLModel, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044f \u0411\u0414 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u0434\u0432\u0438\u0436\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 <code>Department<\/code> \u0438 <code>Staff<\/code>, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044f \u0438\u0445 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 <code>Staff.dept<\/code> \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043b\u044e <code>Department.ident<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438 \u0411\u0414, \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u0430 \u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fb8\/5b3\/5a0\/fb85b35a0e7611040cf00f0d6a17cf7f.png\" width=\"1\" height=\"1\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb8\/5b3\/5a0\/fb85b35a0e7611040cf00f0d6a17cf7f.png\"\/><\/figure>\n<p><a class=\"anchor\" name=\"100\" id=\"100\"><\/a><\/p>\n<h3>The end<\/h3>\n<p>\u0427\u0442\u043e \u0436, \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u044d\u0442\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435; \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044d\u0442\u0430 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0443-\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0438\u0437 SQL, \u0438 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<p>\u0412\u0441\u0435\u0445 \u0441 \u043f\u044f\u0442\u043d\u0438\u0446\u0435\u0439!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/792630\/\"> https:\/\/habr.com\/ru\/articles\/792630\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440)<\/p>\n<p>\u041f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u043f\u043e SQL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u043b\u0430 \u043c\u043d\u0435, \u0434\u0430 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043d\u0435\u0451 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u044e.<\/p>\n<p>\u0412\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f \u0421\u0423\u0411\u0414 SQLite, \u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0451 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0421\u0423\u0411\u0414.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0434\u0443\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0441 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c. \u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u2014 \u043b\u0438\u0441\u0442\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u0437. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430\u043c\u0438, \u0434\u043b\u0438\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u0441 \u043e\u043a\u043e\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 SQL \u0432 Python \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u0435\u043a <code>sqlite3<\/code>, <code>pandas<\/code>,  <code>polars<\/code>. \u042d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0435 \u043f\u043e\u0441\u043e\u0431\u0438\u0435 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f SQL.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u044f \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0432 \u0441\u0432\u043e\u0435\u043c <a href=\"https:\/\/t.me\/+dXZpK8lQ0lY4YjAy\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u043d\u0430\u043b\u0435 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/a>, \u0433\u0434\u0435 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0435\u0442\u043e\u0432, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043a\u043e\u0434\u043e\u043c. \u0410 <a href=\"https:\/\/t.me\/addlist\/qht-ouKSGaQwNjcy\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043f\u0430\u043f\u043a\u0430,<\/a> \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.  <\/p>\n<figure class=\"\"><\/figure>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b SQL \u0437\u0430\u0431\u043e\u0442\u043b\u0438\u0432\u043e \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/gvwilson\/sql-tutorial\/raw\/main\/sql-tutorial.zip\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0435\u0451<\/a> \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0430\u0440\u0445\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 3 \u0433\u0440\u0443\u043f\u043f\u044b \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>.\/db\/*.db<\/code> \u2014 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 SQLite, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043d\u0438\u0436\u0435<\/p>\n<\/li>\n<li>\n<p><code>.\/src\/*.*<\/code> \u2014 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 Python<\/p>\n<\/li>\n<li>\n<p><code>.\/out\/*.*<\/code> \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<p><a href=\"#0\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/a><br \/><a href=\"#1\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b SQL<\/a><br \/><a href=\"#2\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#3\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/a><br \/><a href=\"#4\" rel=\"noopener noreferrer nofollow\">\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/a><br \/><a href=\"#5\" rel=\"noopener noreferrer nofollow\">\u0415\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0432\u043e\u0434\u0430<\/a><br \/><a href=\"#6\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/a><br \/><a href=\"#7\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/a><br \/><a href=\"#8\" rel=\"noopener noreferrer nofollow\">\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438<\/a><br \/><a href=\"#9\" rel=\"noopener noreferrer nofollow\">\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/a><br \/><a href=\"#10\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#11\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0441 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/a><br \/><a href=\"#12\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0432\u043e\u0434 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 WHERE<\/a><br \/><a href=\"#13\" rel=\"noopener noreferrer nofollow\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0441 \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u0435\u043c<\/a><br \/><a href=\"#14\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c NULL \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#15\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 SQL<\/a><br \/><a href=\"#16\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 SQL<\/a><br \/><a href=\"#17\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 COUNT<\/a><br \/><a href=\"#18\" rel=\"noopener noreferrer nofollow\">\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430<\/a><br \/><a href=\"#19\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0441\u0435\u0431\u044f \u0432\u0435\u0434\u0443\u0442 \u043d\u0435\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/a><br \/><a href=\"#20\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u043e\u0440 \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a><br \/><a href=\"#21\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#22\" rel=\"noopener noreferrer nofollow\">\u0427\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434<\/a><br \/><a href=\"#23\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><br \/><a href=\"#24\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/a><br \/><a href=\"#25\" rel=\"noopener noreferrer nofollow\">\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435<\/a><br \/><a href=\"#26\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#27\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#28\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><br \/><a href=\"#29\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 JOIN<\/a><br \/><a href=\"#30\" rel=\"noopener noreferrer nofollow\">INNER JOIN<\/a><br \/><a href=\"#31\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 JOIN \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/a><br \/><a href=\"#32\" rel=\"noopener noreferrer nofollow\">LEFT JOIN<\/a><br \/><a href=\"#33\" rel=\"noopener noreferrer nofollow\">\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 LEFT JOIN<\/a><br \/><a href=\"#34\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#35\" rel=\"noopener noreferrer nofollow\">SELECT DISTINCT \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 WHERE<\/a><br \/><a href=\"#36\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 WHERE \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 IN<\/a><br \/><a href=\"#37\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/a><br \/><a href=\"#38\" rel=\"noopener noreferrer nofollow\">\u0410\u0432\u0442\u043e\u0438\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u0438 PRIMARY KEY<\/a><br \/><a href=\"#39\" rel=\"noopener noreferrer nofollow\">\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 ALTER<\/a><br \/><a href=\"#40\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0442\u0430\u0440\u043e\u0439<\/a><br \/><a href=\"#41\" rel=\"noopener noreferrer nofollow\">\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/a><br \/><a href=\"#42\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438<\/a><br \/><a href=\"#43\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0433\u0440\u0443\u043f\u043f<\/a><br \/><a href=\"#44\" rel=\"noopener noreferrer nofollow\">CTE \u2014 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#45\" rel=\"noopener noreferrer nofollow\">\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e EXPLAIN<\/a><br \/><a href=\"#46\" rel=\"noopener noreferrer nofollow\">\u041d\u0443\u043c\u0435\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#47\" rel=\"noopener noreferrer nofollow\">\u0423\u0441\u043b\u043e\u0432\u0438\u044f if-else<\/a><br \/><a href=\"#48\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SELECT \u0438 CASE<\/a><br \/><a href=\"#49\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#50\" rel=\"noopener noreferrer nofollow\">\u0418\u0449\u0435\u043c \u043f\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE<\/a><br \/><a href=\"#51\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0442\u0440\u043e\u043a\u0438<\/a><br \/><a href=\"#52\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a<\/a><br \/><a href=\"#53\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <\/a><br \/><a href=\"#54\" rel=\"noopener noreferrer nofollow\">\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 SQL<\/a><br \/><a href=\"#55\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/a><br \/><a href=\"#56\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#57\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><br \/><a href=\"#58\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u0430\u0442<\/a><br \/><a href=\"#59\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430 \u0434\u0435\u043d\u044c, \u0431\u0435\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432<\/a><br \/><a href=\"#60\" rel=\"noopener noreferrer nofollow\">JOIN \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 \u0441 \u0441\u043e\u0431\u043e\u0439 \u0436\u0435<\/a><br \/><a href=\"#61\" rel=\"noopener noreferrer nofollow\">\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#62\" rel=\"noopener noreferrer nofollow\">\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u0430\u0440<\/a><br \/><a href=\"#63\" rel=\"noopener noreferrer nofollow\">EXISTS<\/a><br \/><a href=\"#64\" rel=\"noopener noreferrer nofollow\">NOT EXISTS \u0432 SQL<\/a><br \/><a href=\"#65\" rel=\"noopener noreferrer nofollow\">\u041e\u043f\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0435 <\/a><br \/><a href=\"#66\" rel=\"noopener noreferrer nofollow\">\u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><br \/><a href=\"#67\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c PARTITION BY \u0432 SQL<\/a><br \/><a href=\"#68\" rel=\"noopener noreferrer nofollow\">\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 blob<\/a><br \/><a href=\"#69\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 JSON<\/a><br \/><a href=\"#70\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 JSON<\/a><br \/><a href=\"#71\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u0443<\/a><br \/><a href=\"#72\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 JSON<\/a><br \/><a href=\"#73\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435<\/a><br \/><a href=\"#74\" rel=\"noopener noreferrer nofollow\">\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c JSON<\/a><br \/><a href=\"#75\" rel=\"noopener noreferrer nofollow\">Immediate If \u0432 SQL<\/a><br \/><a href=\"#76\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 VIEW \u0432 SQL<\/a><br \/><a href=\"#77\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 CHECK<\/a><br \/><a href=\"#78\" rel=\"noopener noreferrer nofollow\">TRANSACTION \u0432 SQL<\/a><br \/><a href=\"#79\" rel=\"noopener noreferrer nofollow\">ROLLBACK \u0432 SQL<\/a><br \/><a href=\"#80\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u043a\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ROLLBACK<\/a><br \/><a href=\"#81\" rel=\"noopener noreferrer nofollow\">\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/><a href=\"#82\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430<\/a><br \/><a href=\"#83\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/a><br \/><a href=\"#84\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 bi_contact<\/a><br \/><a href=\"#85\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0433\u0440\u0443\u043f\u043f<\/a><br \/><a href=\"#86\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043a\u0438<\/a><br \/><a href=\"#87\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 SQL \u0432 Python \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 sqlite3<\/a><br \/><a href=\"#88\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 <\/a><br \/><a href=\"#89\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CREATE, INSERT, DELETE \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sqlite3<\/a><br \/><a href=\"#90\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/><a href=\"#91\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 Python<\/a><br \/><a href=\"#92\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f SQLite \u0432 Python<\/a><br \/><a href=\"#93\" rel=\"noopener noreferrer nofollow\">Python \u0438 SQLite, \u0435\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/a><br \/><a href=\"#94\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u0442\u043e\u0439 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c<\/a><br \/><a href=\"#95\" rel=\"noopener noreferrer nofollow\">SQL \u0432 Jupyter Notebooks<\/a><br \/><a href=\"#96\" rel=\"noopener noreferrer nofollow\">Pandas \u0438 SQL<\/a><br \/><a href=\"#97\" rel=\"noopener noreferrer nofollow\">Polars \u0438 SQL<\/a><br \/><a href=\"#98\" rel=\"noopener noreferrer nofollow\">ORM<\/a><br \/><a href=\"#99\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 ORM<\/a><br \/><a href=\"#100\" rel=\"noopener noreferrer nofollow\">The end<\/a><\/p>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"0\" id=\"0\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438<\/h3>\n<pre><code class=\"sql\">SELECT * FROM little_penguins; <\/code><\/pre>\n<pre><code>Adelie|Dream|37.2|18.1|178|3900|MALE Adelie|Dream|37.6|19.3|181|3300|FEMALE Gentoo|Biscoe|50|15.3|220|5550|MALE Adelie|Torgersen|37.3|20.5|199|3775|MALE Adelie|Biscoe|39.6|17.7|186|3500|FEMALE Gentoo|Biscoe|47.7|15|216|4750|FEMALE Adelie|Dream|36.5|18|182|3150|FEMALE Gentoo|Biscoe|42|13.5|210|4150|FEMALE Adelie|Torgersen|42.1|19.1|195|4000|MALE Gentoo|Biscoe|54.3|15.7|231|5650|MALE <\/code><\/pre>\n<ul>\n<li>\n<p>\u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b SQL<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/admin_commands.sql\" rel=\"noopener noreferrer nofollow\">src\/admin_commands.sql<\/a><\/p>\n<pre><code class=\"sql\">.headers on  .mode markdown SELECT * FROM little_penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/admin_commands.out\" rel=\"noopener noreferrer nofollow\">out\/admin_commands.out<\/a><\/p>\n<pre><code>| species |  island   | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g |  sex   | |---------|-----------|----------------|---------------|-------------------|-------------|--------| | Adelie  | Dream     | 37.2           | 18.1          | 178               | 3900        | MALE   | | Adelie  | Dream     | 37.6           | 19.3          | 181               | 3300        | FEMALE | | Gentoo  | Biscoe    | 50             | 15.3          | 220               | 5550        | MALE   | | Adelie  | Torgersen | 37.3           | 20.5          | 199               | 3775        | MALE   | | Adelie  | Biscoe    | 39.6           | 17.7          | 186               | 3500        | FEMALE | | Gentoo  | Biscoe    | 47.7           | 15            | 216               | 4750        | FEMALE | | Adelie  | Dream     | 36.5           | 18            | 182               | 3150        | FEMALE | | Gentoo  | Biscoe    | 42             | 13.5          | 210               | 4150        | FEMALE | | Adelie  | Torgersen | 42.1           | 19.1          | 195               | 4000        | MALE   | | Gentoo  | Biscoe    | 54.3           | 15.7          | 231               | 5650        | MALE   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0440\u0435\u0436\u0438\u043c markdown; \u0432 <code>SQLite<\/code> \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 <code>.<\/code>, \u0430 \u0432 PostgreSQL \u0441 <code>\\<\/code><\/p>\n<\/li>\n<li>\n<p>\u043a\u0441\u0442\u0430\u0442\u0438, \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u044b \u0438\u043b\u0438 \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0435\u0441\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>.help<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/specify_columns.sql\" rel=\"noopener noreferrer nofollow\">src\/specify_columns.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        island,        sex FROM little_penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/specify_columns.out\" rel=\"noopener noreferrer nofollow\">out\/specify_columns.out<\/a><\/p>\n<pre><code>| species |  island   |  sex   | |---------|-----------|--------| | Adelie  | Dream     | MALE   | | Adelie  | Dream     | FEMALE | | Gentoo  | Biscoe    | MALE   | | Adelie  | Torgersen | MALE   | | Adelie  | Biscoe    | FEMALE | | Gentoo  | Biscoe    | FEMALE | | Adelie  | Dream     | FEMALE | | Gentoo  | Biscoe    | FEMALE | | Adelie  | Torgersen | MALE   | | Gentoo  | Biscoe    | MALE   | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0438 <code>species<\/code>, <code>island<\/code>, <code>sex<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/sort.sql\" rel=\"noopener noreferrer nofollow\">src\/sort.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM little_penguins ORDER BY island ASC,          sex DESC; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/sort.out\" rel=\"noopener noreferrer nofollow\">out\/sort.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Gentoo  | MALE   | Biscoe    | | Gentoo  | MALE   | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Gentoo  | FEMALE | Biscoe    | | Gentoo  | FEMALE | Biscoe    | | Adelie  | MALE   | Dream     | | Adelie  | FEMALE | Dream     | | Adelie  | FEMALE | Dream     | | Adelie  | MALE   | Torgersen | | Adelie  | MALE   | Torgersen | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>island<\/code>, <code>sex<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>little_penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>island<\/code> \u0432 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u043e\u0442 A \u043a Z)<\/p>\n<\/li>\n<li>\n<p>\u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 <code>island<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c <code>sex<\/code> \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a \u043c\u0435\u043d\u044c\u0448\u0435\u043c\u0443 (\u043e\u0442 Z \u043a A)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/limit.sql\" rel=\"noopener noreferrer nofollow\">src\/limit.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM penguins ORDER BY species,          sex,          island LIMIT 10; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/limit.out\" rel=\"noopener noreferrer nofollow\">out\/limit.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Adelie  |        | Dream     | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0438 <code>penguins<\/code><\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e <code>species<\/code> \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f, \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>species<\/code> \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e <code>sex<\/code>, \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c <code>sex<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e <code>island<\/code><\/p>\n<\/li>\n<li>\n<p>\u043d\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 10 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h3>\u0415\u0449\u0451 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0432\u043e\u0434\u0430<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/page.sql\" rel=\"noopener noreferrer nofollow\">src\/page.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT species,        sex,        island FROM penguins ORDER BY species,          sex,          island LIMIT 10 OFFSET 3; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/page.out\" rel=\"noopener noreferrer nofollow\">out\/page.out<\/a><\/p>\n<pre><code>| species |  sex   |  island   | |---------|--------|-----------| | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  |        | Torgersen | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | | Adelie  | FEMALE | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p><code>OFFSET<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 <code>LIMIT<\/code> \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b 3 \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h3>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/distinct.sql\" rel=\"noopener noreferrer nofollow\">src\/distinct.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/distinct.out\" rel=\"noopener noreferrer nofollow\">out\/distinct.out<\/a><\/p>\n<pre><code>|  species  |  sex   |  island   | |-----------|--------|-----------| | Adelie    | MALE   | Torgersen | | Adelie    | FEMALE | Torgersen | | Adelie    |        | Torgersen | | Adelie    | FEMALE | Biscoe    | | Adelie    | MALE   | Biscoe    | | Adelie    | FEMALE | Dream     | | Adelie    | MALE   | Dream     | | Adelie    |        | Dream     | | Chinstrap | FEMALE | Dream     | | Chinstrap | MALE   | Dream     | | Gentoo    | FEMALE | Biscoe    | | Gentoo    | MALE   | Biscoe    | | Gentoo    |        | Biscoe    | <\/code><\/pre>\n<ul>\n<li>\n<p><code>SELECT DISTINCT<\/code> \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code><\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<p><a class=\"anchor\" name=\"7\" id=\"7\"><\/a><\/p>\n<h3>\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/src\/filter.sql\" rel=\"noopener noreferrer nofollow\">src\/filter.sql<\/a><\/p>\n<pre><code class=\"sql\">SELECT DISTINCT species,                 sex,                 island FROM penguins WHERE island = 'Biscoe'; <\/code><\/pre>\n<p><a href=\"https:\/\/gvwilson.github.io\/sql-tutorial\/out\/filter.out\" rel=\"noopener noreferrer nofollow\">out\/filter.out<\/a><\/p>\n<pre><code>| species |  sex   | island | |---------|--------|--------| | Adelie  | FEMALE | Biscoe | | Adelie  | MALE   | Biscoe | | Gentoo  | FEMALE | Biscoe | | Gentoo  | MALE   | Biscoe | | Gentoo  |        | Biscoe | <\/code><\/pre>\n<ul>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>species<\/code>, <code>sex<\/code>, <code>island<\/code> \u0438\u0437 <code>penguins<\/code>,<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-367794","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=367794"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367794\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}