{"id":374786,"date":"2024-05-21T06:08:49","date_gmt":"2024-05-21T06:08:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=374786"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=374786","title":{"rendered":"<span>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0435<\/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<h2>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043f\u043e SQL \u043d\u0430 stepik.org \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430:   <\/p>\n<blockquote>\n<p>\u0412\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>Files<\/code>, \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u0430\u043f\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/p>\n<\/blockquote>\n<pre><code class=\"bash\">+----+--------------------------+---------------------+ | id | name                     | parent_directory_id | +----+--------------------------+---------------------+ | 1  | deskop                   | NULL                | | 2  | test                     | 1                   | | 3  | \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438                 | 2                   | | 4  | 1.jpg                    | 3                   | | 5  | avatar.png               | 3                   | | 6  | certificate.png          | 3                   | | 7  | py.png                   | 3                   | | 8  | World_Time_Zones_Map.png | 3                   | | 9  | \u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430.png        | 3                   | | 10 | \u041d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430.djvu         | 2                   | | 11 | \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b                | 2                   | | 12 | image_util.py            | 11                  | | 13 | sort.py                  | 11                  | | 14 | \u0420\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b             | 2                   | | 15 | astros.json              | 14                  | +----+--------------------------+---------------------+<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0449\u0438\u0439 \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u0430\u043f\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0438 \u043f\u0443\u0442\u044c \u0434\u043e \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<p><code>...\/&lt;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u043f\u0430\u043f\u043a\u0438>\/&lt;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0438><\/code><\/p>\n<\/blockquote>\n<figure class=\"bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d13\/c66\/1b0\/d13c661b0fe98598ca3b99ce67ae35c3.png\" alt=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435\" title=\"\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435\" width=\"475\" height=\"263\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d13\/c66\/1b0\/d13c661b0fe98598ca3b99ce67ae35c3.png\"\/><\/p>\n<div><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c (Common Table Expression &#8212; \u0434\u0430\u043b\u0435\u0435 CTE), \u043d\u043e \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u00ab\u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0430\u00bb &#8212; \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0430\u043a\u0443\u044e &#171;\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443&#187; SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c&#8230;<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0441\u0442\u0440\u043e &#171;\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0433\u043b\u0430\u0437\u0430\u043c\u0438&#187; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#8212; \u0431\u044b\u043b\u0430 \u0431\u044b \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f, \u0430 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f.<\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u0447\u0435\u0433\u043e-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0435 \u0434\u0430\u043b, \u0438 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<p><strong>\u0418\u0442\u0430\u043a<\/strong>, \u0434\u0430\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Adjacency_list\" rel=\"noopener noreferrer nofollow\">Adjacency list<\/a> &#8212; &#171;\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u043c\u0435\u0436\u043d\u043e\u0441\u0442\u0438&#187;). \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c (\u043d\u043e \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0438\u043c):<\/p>\n<ul>\n<li>\n<p>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (\u0418\u0414)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u044f (\u043d\u0435\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435), \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b UTF-8<\/p>\n<\/li>\n<li>\n<p>\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0440\u0430\u0432\u043d\u044b\u0439 <code>NULL<\/code> \u0434\u043b\u044f \u0443\u0437\u043b\u043e\u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e<\/em> (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c CTE) SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0432\u044b\u0448\u0435, \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u0441\u0442\u0443\u043f \u0432 4\u00a0\u0441\u0438\u043c\u0432\u043e\u043b\u0430<\/p>\n<\/li>\n<li>\n<p>\u0423\u0437\u043b\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u00a0\u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u044f\u043c\u044b\u0435 &#171;\u043f\u043e\u0442\u043e\u043c\u043a\u0438&#187; \u043e\u0434\u043d\u043e\u0433\u043e &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f&#187; \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0432\u0435\u0442\u0432\u044f\u0445 \u0432\u0438\u0434\u0430 <code>\"\u251c\u2500\u2500\"<\/code>, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u043d\u0430 <code>\"\u2514\u2500\u2500\"<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u0432\u0435\u0442\u0432\u0438 \u0438\u043c\u0435\u044e\u0442 \u0432\u0438\u0434 <code>\"\u2502  \"<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0442\u0432\u0438 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0421\u0423\u0411\u0414: MySQL, SQLite, PostgreSQL (\u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0421\u0423\u0411\u0414 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438).<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e<\/h2>\n<p>\u042f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 &#8212; \u043e\u0444\u043e\u0440\u043c\u0438\u043b \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 CTE, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u0436\u0434\u044b\u0439:<\/p>\n<ol>\n<li>\n<p><strong>Mapping<\/strong>: \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 \u043a \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u043c\u0443. \u041f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043b\u044e\u0431\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u0432 Mapping \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Levels<\/strong>: \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 CTE, \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0449\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0418\u0414 \u00ab\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439\u00bb \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 (parents), \u0438 \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u043c\u044f \u0443\u0437\u043b\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u00ab\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439\u00bb (full_path). <br \/> \u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 node_level \u0442\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c\u0441\u044f, \u0445\u043e\u0442\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043e\u043d \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p><strong>Branches<\/strong>: CTE, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0438\u0434 \u00ab\u0432\u0435\u0442\u043a\u0438\u00bb \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u00ab\u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435\u00bb \u0432\u0435\u0442\u043a\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0445 \u00ab\u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438\u00bb. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 CTE \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e <code>WindowByParents<\/code> \u0441 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044e <code>Levels.parents<\/code>, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>LAST_VALUE(id) OVER WindowByParents<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043e\u0431\u044b\u0439 \u0432\u0438\u0434 \u00ab\u0432\u0435\u0442\u0432\u0438\u00bb \u0434\u043b\u044f \u00ab\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445\u00bb \u0443\u0437\u043b\u043e\u0432 \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<li>\n<p><strong>Tree<\/strong>: \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 CTE, \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0449\u0435\u0435 \u0432\u0441\u0435 \u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u00ab\u0432\u0435\u0442\u043a\u0438\u00bb \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0443\u0437\u043b\u0430 \u0432 \u043f\u043e\u043b\u0435 <code>all_through<\/code><\/p>\n<\/li>\n<li>\n<p><strong>FineTree<\/strong>: \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 CTE, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0435\u0435 \u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u0432\u0435\u0442\u043a\u0438, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0442\u043a\u0438 \u0438 \u0438\u043c\u0435\u043d\u0430 \u0443\u0437\u043b\u043e\u0432 \u0432 \u043f\u043e\u043b\u0435 <code>fine_tree<\/code>. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0432 <em>\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435<\/em> \u0438\u0437 <code>FineTree<\/code>, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0432 \u043d\u0435\u043c \u043f\u043e\u043b\u0435\u0439, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439, \u043a\u0440\u043e\u043c\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u00ab\u0432\u0435\u0442\u0432\u0435\u0439\u00bb, \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u043d\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043e\u0431\u043b\u044e\u0441\u0442\u0438 \u00ab\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u00bb CTE, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 CTE \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<p><em>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440 \u043f\u043e \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044e: \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f ALLCAPS. \u0410\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430, \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 <\/em><a href=\"https:\/\/www.sqlstyle.guide\/ru\/#%D0%B7%D0%B0%D1%80%D0%B5%D0%B7%D0%B5%D1%80%D0%B2%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D1%8B%D0%B5-%D1%81%D0%BB%D0%BE%D0%B2%D0%B0\" rel=\"noopener noreferrer nofollow\"><em>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443 \u043f\u043e \u0441\u0442\u0438\u043b\u044e SQL<\/em><\/a><em> \u0432 \u044d\u0442\u043e\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u0435 \u0441 \u043c\u043e\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e.<\/em><\/p>\n<h2>\u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0432 MySQL \u0438 SQLite<\/h2>\n<p>\u0412\u044b\u0431\u0440\u0430\u043b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u0432\u0435 \u0421\u0423\u0411\u0414:<\/p>\n<ul>\n<li>\n<p><strong>MySQL<\/strong>, \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0421\u0423\u0411\u0414, \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 \u0444\u043e\u0440\u043a\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>SQLite<\/strong> \u0432\u043e\u043e\u0431\u0449\u0435 \u0447\u0435\u043c\u043f\u0438\u043e\u043d \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u044c, \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0431\u043e\u0433\u0430\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438 CTE, \u0438 \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0431\u044a\u0435\u043c\u0435 (\u0438 \u0441\u0432\u0435\u0440\u0445 \u0442\u043e\u0433\u043e)<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u0440\u0435\u0434\u0430\u0445.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043a <a href=\"https:\/\/stepik.org\/lesson\/1195940\/step\/2?unit=1230007\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435<\/a> \u0432 <a href=\"https:\/\/stepik.org\/course\/113918\/info\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u043c \u0441\u0430\u043c\u043e\u043c \u043a\u0443\u0440\u0441\u0435 \u043f\u043e SQL<\/a>, \u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u044f\u0442 \u043c\u0435\u043d\u044f \u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"sql\">DROP TABLE IF EXISTS Files; CREATE TABLE Files (     id                  INT,     name                VARCHAR(40),     parent_directory_id INT );  INSERT INTO Files (id, name, parent_directory_id) VALUES (1, 'desktop', NULL),        (2, 'test', 1),        (3, '\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438', 2),        (4, '1.jpg', 3),        (5, 'avatar.png', 3),        (6, 'certificate.png', 3),        (7, 'py.png', 3),        (8, 'World_Time_Zones_Map.png', 3),        (9, '\u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430.png', 3),        (10, '\u041d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430.djvu', 2),        (11, '\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b', 2),        (12, 'image_util.py', 11),        (13, 'sort.py', 11),        (14, '\u0420\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b', 2),        (15, 'astros.json', 14);<\/code><\/pre>\n<h3>Mapping<\/h3>\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_directory_id as parent_node_id, name as node_name from Files ),<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Files<\/code> \u0438 \u0438\u043c\u0435\u043d\u0430 \u0435\u0435 \u043f\u043e\u043b\u0435\u0439 \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435   <\/p>\n<h3>Levels<\/h3>\n<pre><code class=\"sql\">Levels as ( select  node_id, parent_node_id, node_name, cast(parent_node_id as char(2000)) as parents, cast(node_name as char(2000)) as full_path, 0 as node_level from Mapping where parent_node_id is null  union  select  Mapping.node_id,  Mapping.parent_node_id, Mapping.node_name, concat(coalesce(concat(prev.parents, '-'), ''), cast(Mapping.parent_node_id as char)), concat_ws(' ', prev.full_path, Mapping.node_name), prev.node_level + 1 from  Levels as prev inner join Mapping on Mapping.parent_node_id = prev.node_id ),<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u043c CTE \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439. \u0412 MySQL \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f  <code>CHAR<\/code>, \u0430 <code>VARCHAR<\/code> \u0438\u043b\u0438 <code>TEXT<\/code> \u0432\u044b\u0434\u0430\u0434\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. <br \/>SQLite \u0437\u0434\u0435\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u0435\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043d, \u0432 \u043d\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0432\u043d\u043e\u0446\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0442\u0438\u043f\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>CHAR<\/code> \u043a\u0430\u043a \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<p>\u041f\u043e\u043b\u0435 <code>full_path<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u0430\u043d\u043d\u043e\u043c\u0443, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0443\u0437\u043b\u043e\u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043f\u0440\u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0435, \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438 \u0431<em>\u043e<\/em>\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#8212; \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u043d\u0430\u0445 \u0443\u0437\u043b\u043e\u0432. <br \/>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 &#171;\u0443\u043f\u0430\u0434\u0435\u0442&#187; \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0432\u0438\u0434\u0430 <code>Data truncation: Data too long for column 'full_path'<\/code> &#8212; \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043f\u043e\u043b\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432 <code>parents<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>\"-\"<\/code>, \u0430 \u0434\u043b\u044f <code>full_path<\/code> &#8212; \u0441\u0438\u043c\u0432\u043e\u043b \u043f\u0440\u043e\u0431\u0435\u043b\u0430 <code>CHAR(32)<\/code>, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c &#171;\u043c\u0435\u043d\u044c\u0448\u0435&#187; \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 <code>node_name<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0441 \u0443\u0447\u0435\u0442\u043e\u043c &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445&#187; \u0443\u0437\u043b\u043e\u0432. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<h3>Branches<\/h3>\n<pre><code class=\"sql\">Branches as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '\u2514\u2500\u2500 '  else '\u251c\u2500\u2500 '  end  else ''  end as node_branch, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '    '  else '\u2502   '  end  else ''  end as branch_through from Levels  window WindowByParents as ( partition by parents  order by node_name rows between current row and unbounded following  ) order by full_path ),<\/code><\/pre>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 <code>CASE WHEN \u2026 END<\/code> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 <code>IF()<\/code>, \u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0421\u0423\u0411\u0414 \u043d\u0438\u0436\u0435, \u043a\u0430\u043a \u0438 &#171;\u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c&#187;.<\/p>\n<h3>Tree<\/h3>\n<pre><code class=\"sql\">Tree as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, node_branch, cast(branch_through as char(2000)) as all_through from Branches where parent_node_id is null  union  select  Branches.node_id, Branches.parent_node_id, Branches.node_name, Branches.parents, Branches.full_path, Branches.node_level, Branches.node_branch, concat(prev.all_through, Branches.branch_through) from  Tree as prev inner join Branches on Branches.parent_node_id = prev.node_id ),<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043f\u043e\u043b\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u00ab\u0441\u043a\u0432\u043e\u0437\u043d\u044b\u043c\u0438 \u0432\u0435\u0442\u0432\u044f\u043c\u0438\u00bb <code>all_through<\/code><\/p>\n<p><em>\u041c\u044b \u043f\u043e\u0447\u0442\u0438 \u0443 \u0446\u0435\u043b\u0438!<\/em><\/p>\n<h3>FineTree<\/h3>\n<pre><code class=\"sql\">FineTree as ( select  tr.node_id, tr.parent_node_id, tr.node_name, tr.parents, tr.full_path, tr.node_level, concat(coalesce(parent.all_through, ''), tr.node_branch, tr.node_name) as fine_tree from  Tree as tr left join Tree as parent on parent.node_id = tr.parent_node_id order by tr.full_path )  select fine_tree from FineTree ;<\/code><\/pre>\n<p>\u0414\u043b\u0438\u043d\u0430 \u043f\u043e\u043b\u044f <code>fine_tree<\/code> \u0431\u0443\u0434\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 \u0442\u0435\u043c\u0438 \u0436\u0435 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c 450 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 (4 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c + \u0434\u043e 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u043c\u044f \u0443\u0437\u043b\u0430), \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u043d\u0441\u0442\u0440\u043e\u0432.<\/p>\n<p><em>\u0412\u0443\u0430\u043b\u044f:<\/em><\/p>\n<pre><code>fine_tree                           | ------------------------------------+ desktop                             | \u2514\u2500\u2500 test                            |     \u251c\u2500\u2500 \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438                    |     \u2502   \u251c\u2500\u2500 1.jpg                   |     \u2502   \u251c\u2500\u2500 avatar.png              |     \u2502   \u251c\u2500\u2500 certificate.png         |     \u2502   \u251c\u2500\u2500 py.png                  |     \u2502   \u251c\u2500\u2500 World_Time_Zones_Map.png|     \u2502   \u2514\u2500\u2500 \u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430.png       |     \u251c\u2500\u2500 \u041d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430.djvu            |     \u251c\u2500\u2500 \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b                   |     \u2502   \u251c\u2500\u2500 image_util.py           |     \u2502   \u2514\u2500\u2500 sort.py                 |     \u2514\u2500\u2500 \u0420\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b                |         \u2514\u2500\u2500 astros.json             |<\/code><\/pre>\n<p>\u0412 MySQL \u0438 SQLite \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d<\/p>\n<h2>All Together Now<\/h2>\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_directory_id as parent_node_id, name as node_name from Files ),  Levels as ( select  node_id, parent_node_id, node_name, cast(parent_node_id as char(2000)) as parents, cast(node_name as char(2000)) as full_path, 0 as node_level from Mapping where parent_node_id is null  union  select  Mapping.node_id,  Mapping.parent_node_id, Mapping.node_name, concat(coalesce(concat(prev.parents, '-'), ''), cast(Mapping.parent_node_id as char)), concat_ws(' ', prev.full_path, Mapping.node_name), prev.node_level + 1 from  Levels as prev inner join Mapping on Mapping.parent_node_id = prev.node_id ),  Branches as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '\u2514\u2500\u2500 '  else '\u251c\u2500\u2500 '  end  else ''  end as node_branch, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '    '  else '\u2502   '  end  else ''  end as branch_through from Levels  window WindowByParents as ( partition by parents  order by node_name rows between current row and unbounded following  ) order by full_path ),  Tree as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, node_branch, cast(branch_through as char(2000)) as all_through from Branches where parent_node_id is null  union  select  Branches.node_id, Branches.parent_node_id, Branches.node_name, Branches.parents, Branches.full_path, Branches.node_level, Branches.node_branch, concat(prev.all_through, Branches.branch_through) from  Tree as prev inner join Branches on Branches.parent_node_id = prev.node_id ),  FineTree as ( select  tr.node_id, tr.parent_node_id, tr.node_name, tr.parents, tr.full_path, tr.node_level, concat(coalesce(parent.all_through, ''), tr.node_branch, tr.node_name) as fine_tree from  Tree as tr left join Tree as parent on parent.node_id = tr.parent_node_id order by tr.full_path )  select fine_tree from FineTree ;<\/code><\/pre>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u0441\u0430\u043c\u043e\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 &#171;\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438&#187; CTE \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c, \u043d\u043e \u0437\u0430\u0442\u043e \u0442\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/810855\/\" rel=\"noopener noreferrer nofollow\"><em>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442<\/em><\/a><em> \u2013 \u0432 \u043d\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u0432\u0441\u0435\u0439, \u0430 \u0447\u0430\u0441\u0442\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438, \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 \u0432 MySQL \u0438 SQLite, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <\/em><\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a href=\"https:\/\/www.databasestar.com\/hierarchical-data-sql\/\" rel=\"noopener noreferrer nofollow\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0432 SQL (En)<\/a><\/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\/810687\/\"> https:\/\/habr.com\/ru\/articles\/810687\/<\/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<h2>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043f\u043e SQL \u043d\u0430 stepik.org \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430:   <\/p>\n<blockquote>\n<p>\u0412\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>Files<\/code>, \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u0430\u043f\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/p>\n<\/blockquote>\n<pre><code class=\"bash\">+----+--------------------------+---------------------+ | id | name                     | parent_directory_id | +----+--------------------------+---------------------+ | 1  | deskop                   | NULL                | | 2  | test                     | 1                   | | 3  | \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438                 | 2                   | | 4  | 1.jpg                    | 3                   | | 5  | avatar.png               | 3                   | | 6  | certificate.png          | 3                   | | 7  | py.png                   | 3                   | | 8  | World_Time_Zones_Map.png | 3                   | | 9  | \u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430.png        | 3                   | | 10 | \u041d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430.djvu         | 2                   | | 11 | \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b                | 2                   | | 12 | image_util.py            | 11                  | | 13 | sort.py                  | 11                  | | 14 | \u0420\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b             | 2                   | | 15 | astros.json              | 14                  | +----+--------------------------+---------------------+<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0449\u0438\u0439 \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u0430\u043f\u043e\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0438 \u043f\u0443\u0442\u044c \u0434\u043e \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<p><code>...\/&lt;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u043f\u0430\u043f\u043a\u0438>\/&lt;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u043f\u0430\u043f\u043a\u0438><\/code><\/p>\n<\/blockquote>\n<figure class=\"bordered\">\n<div><figcaption>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c (Common Table Expression &#8212; \u0434\u0430\u043b\u0435\u0435 CTE), \u043d\u043e \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u00ab\u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0430\u00bb &#8212; \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0430\u043a\u0443\u044e &#171;\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443&#187; SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0430 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c&#8230;<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0441\u0442\u0440\u043e &#171;\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0433\u043b\u0430\u0437\u0430\u043c\u0438&#187; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#8212; \u0431\u044b\u043b\u0430 \u0431\u044b \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f, \u0430 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f.<\/p>\n<p>\u041f\u043e\u0438\u0441\u043a \u0447\u0435\u0433\u043e-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0435 \u0434\u0430\u043b, \u0438 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<p><strong>\u0418\u0442\u0430\u043a<\/strong>, \u0434\u0430\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Adjacency_list\" rel=\"noopener noreferrer nofollow\">Adjacency list<\/a> &#8212; &#171;\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u043c\u0435\u0436\u043d\u043e\u0441\u0442\u0438&#187;). \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c (\u043d\u043e \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0438\u043c):<\/p>\n<ul>\n<li>\n<p>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (\u0418\u0414)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u044f (\u043d\u0435\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435), \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b UTF-8<\/p>\n<\/li>\n<li>\n<p>\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0440\u0430\u0432\u043d\u044b\u0439 <code>NULL<\/code> \u0434\u043b\u044f \u0443\u0437\u043b\u043e\u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e<\/em> (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c CTE) SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0432\u044b\u0448\u0435, \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u0441\u0442\u0443\u043f \u0432 4\u00a0\u0441\u0438\u043c\u0432\u043e\u043b\u0430<\/p>\n<\/li>\n<li>\n<p>\u0423\u0437\u043b\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u00a0\u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u044f\u043c\u044b\u0435 &#171;\u043f\u043e\u0442\u043e\u043c\u043a\u0438&#187; \u043e\u0434\u043d\u043e\u0433\u043e &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f&#187; \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0432\u0435\u0442\u0432\u044f\u0445 \u0432\u0438\u0434\u0430 <code>\"\u251c\u2500\u2500\"<\/code>, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u043d\u0430 <code>\"\u2514\u2500\u2500\"<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u0432\u0435\u0442\u0432\u0438 \u0438\u043c\u0435\u044e\u0442 \u0432\u0438\u0434 <code>\"\u2502  \"<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0442\u0432\u0438 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0421\u0423\u0411\u0414: MySQL, SQLite, PostgreSQL (\u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0421\u0423\u0411\u0414 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438).<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e<\/h2>\n<p>\u042f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 &#8212; \u043e\u0444\u043e\u0440\u043c\u0438\u043b \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 CTE, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u0436\u0434\u044b\u0439:<\/p>\n<ol>\n<li>\n<p><strong>Mapping<\/strong>: \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435 \u043a \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u043c\u0443. \u041f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043b\u044e\u0431\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u0432 Mapping \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Levels<\/strong>: \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 CTE, \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0449\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0418\u0414 \u00ab\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439\u00bb \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 (parents), \u0438 \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u043c\u044f \u0443\u0437\u043b\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u00ab\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439\u00bb (full_path). <br \/> \u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 node_level \u0442\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c\u0441\u044f, \u0445\u043e\u0442\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043e\u043d \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f<\/p>\n<\/li>\n<li>\n<p><strong>Branches<\/strong>: CTE, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0438\u0434 \u00ab\u0432\u0435\u0442\u043a\u0438\u00bb \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u00ab\u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435\u00bb \u0432\u0435\u0442\u043a\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0445 \u00ab\u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c\u0438\u00bb. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 CTE \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e <code>WindowByParents<\/code> \u0441 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044e <code>Levels.parents<\/code>, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>LAST_VALUE(id) OVER WindowByParents<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043e\u0431\u044b\u0439 \u0432\u0438\u0434 \u00ab\u0432\u0435\u0442\u0432\u0438\u00bb \u0434\u043b\u044f \u00ab\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445\u00bb \u0443\u0437\u043b\u043e\u0432 \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<li>\n<p><strong>Tree<\/strong>: \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0435 CTE, \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0449\u0435\u0435 \u0432\u0441\u0435 \u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u00ab\u0432\u0435\u0442\u043a\u0438\u00bb \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 \u0443\u0437\u043b\u0430 \u0432 \u043f\u043e\u043b\u0435 <code>all_through<\/code><\/p>\n<\/li>\n<li>\n<p><strong>FineTree<\/strong>: \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 CTE, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0435\u0435 \u0441\u043a\u0432\u043e\u0437\u043d\u044b\u0435 \u0432\u0435\u0442\u043a\u0438, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0442\u043a\u0438 \u0438 \u0438\u043c\u0435\u043d\u0430 \u0443\u0437\u043b\u043e\u0432 \u0432 \u043f\u043e\u043b\u0435 <code>fine_tree<\/code>. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0432 <em>\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435<\/em> \u0438\u0437 <code>FineTree<\/code>, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0432 \u043d\u0435\u043c \u043f\u043e\u043b\u0435\u0439, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439, \u043a\u0440\u043e\u043c\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u00ab\u0432\u0435\u0442\u0432\u0435\u0439\u00bb, \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u043d\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043e\u0431\u043b\u044e\u0441\u0442\u0438 \u00ab\u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u00bb CTE, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 CTE \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<p><em>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440 \u043f\u043e \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044e: \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f ALLCAPS. \u0410\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430, \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 <\/em><a href=\"https:\/\/www.sqlstyle.guide\/ru\/#%D0%B7%D0%B0%D1%80%D0%B5%D0%B7%D0%B5%D1%80%D0%B2%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D1%8B%D0%B5-%D1%81%D0%BB%D0%BE%D0%B2%D0%B0\" rel=\"noopener noreferrer nofollow\"><em>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443 \u043f\u043e \u0441\u0442\u0438\u043b\u044e SQL<\/em><\/a><em> \u0432 \u044d\u0442\u043e\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u0435 \u0441 \u043c\u043e\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e.<\/em><\/p>\n<h2>\u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0432 MySQL \u0438 SQLite<\/h2>\n<p>\u0412\u044b\u0431\u0440\u0430\u043b \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u0432\u0435 \u0421\u0423\u0411\u0414:<\/p>\n<ul>\n<li>\n<p><strong>MySQL<\/strong>, \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0421\u0423\u0411\u0414, \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 \u0444\u043e\u0440\u043a\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>SQLite<\/strong> \u0432\u043e\u043e\u0431\u0449\u0435 \u0447\u0435\u043c\u043f\u0438\u043e\u043d \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u044c, \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0431\u043e\u0433\u0430\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438 CTE, \u0438 \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0431\u044a\u0435\u043c\u0435 (\u0438 \u0441\u0432\u0435\u0440\u0445 \u0442\u043e\u0433\u043e)<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u0440\u0435\u0434\u0430\u0445.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043a <a href=\"https:\/\/stepik.org\/lesson\/1195940\/step\/2?unit=1230007\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435<\/a> \u0432 <a href=\"https:\/\/stepik.org\/course\/113918\/info\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u043c \u0441\u0430\u043c\u043e\u043c \u043a\u0443\u0440\u0441\u0435 \u043f\u043e SQL<\/a>, \u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u044f\u0442 \u043c\u0435\u043d\u044f \u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"sql\">DROP TABLE IF EXISTS Files; CREATE TABLE Files (     id                  INT,     name                VARCHAR(40),     parent_directory_id INT );  INSERT INTO Files (id, name, parent_directory_id) VALUES (1, 'desktop', NULL),        (2, 'test', 1),        (3, '\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438', 2),        (4, '1.jpg', 3),        (5, 'avatar.png', 3),        (6, 'certificate.png', 3),        (7, 'py.png', 3),        (8, 'World_Time_Zones_Map.png', 3),        (9, '\u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430.png', 3),        (10, '\u041d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430.djvu', 2),        (11, '\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b', 2),        (12, 'image_util.py', 11),        (13, 'sort.py', 11),        (14, '\u0420\u0430\u0437\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b', 2),        (15, 'astros.json', 14);<\/code><\/pre>\n<h3>Mapping<\/h3>\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_directory_id as parent_node_id, name as node_name from Files ),<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>Files<\/code> \u0438 \u0438\u043c\u0435\u043d\u0430 \u0435\u0435 \u043f\u043e\u043b\u0435\u0439 \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435   <\/p>\n<h3>Levels<\/h3>\n<pre><code class=\"sql\">Levels as ( select  node_id, parent_node_id, node_name, cast(parent_node_id as char(2000)) as parents, cast(node_name as char(2000)) as full_path, 0 as node_level from Mapping where parent_node_id is null  union  select  Mapping.node_id,  Mapping.parent_node_id, Mapping.node_name, concat(coalesce(concat(prev.parents, '-'), ''), cast(Mapping.parent_node_id as char)), concat_ws(' ', prev.full_path, Mapping.node_name), prev.node_level + 1 from  Levels as prev inner join Mapping on Mapping.parent_node_id = prev.node_id ),<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u043c CTE \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439. \u0412 MySQL \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f  <code>CHAR<\/code>, \u0430 <code>VARCHAR<\/code> \u0438\u043b\u0438 <code>TEXT<\/code> \u0432\u044b\u0434\u0430\u0434\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. <br \/>SQLite \u0437\u0434\u0435\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u0435\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043d, \u0432 \u043d\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0432\u043d\u043e\u0446\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0442\u0438\u043f\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>CHAR<\/code> \u043a\u0430\u043a \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<p>\u041f\u043e\u043b\u0435 <code>full_path<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u043d\u0430 \u043f\u0443\u0442\u0438 \u0434\u0430\u043d\u043d\u043e\u043c\u0443, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0443\u0437\u043b\u043e\u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043f\u0440\u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0435, \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438 \u0431<em>\u043e<\/em>\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#8212; \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u043d\u0430\u0445 \u0443\u0437\u043b\u043e\u0432. <br \/>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 &#171;\u0443\u043f\u0430\u0434\u0435\u0442&#187; \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0432\u0438\u0434\u0430 <code>Data truncation: Data too long for column 'full_path'<\/code> &#8212; \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043f\u043e\u043b\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432 <code>parents<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>\"-\"<\/code>, \u0430 \u0434\u043b\u044f <code>full_path<\/code> &#8212; \u0441\u0438\u043c\u0432\u043e\u043b \u043f\u0440\u043e\u0431\u0435\u043b\u0430 <code>CHAR(32)<\/code>, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c &#171;\u043c\u0435\u043d\u044c\u0448\u0435&#187; \u043b\u044e\u0431\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 <code>node_name<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0441 \u0443\u0447\u0435\u0442\u043e\u043c &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445&#187; \u0443\u0437\u043b\u043e\u0432. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<h3>Branches<\/h3>\n<pre><code class=\"sql\">Branches as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '\u2514\u2500\u2500 '  else '\u251c\u2500\u2500 '  end  else ''  end as node_branch, case  when parent_node_id is not null then  case  when node_id = last_value(node_id) over WindowByParents then '    '  else '\u2502   '  end  else ''  end as branch_through from Levels  window WindowByParents as ( partition by parents  order by node_name rows between current row and unbounded following  ) order by full_path ),<\/code><\/pre>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 <code>CASE WHEN \u2026 END<\/code> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 <code>IF()<\/code>, \u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0421\u0423\u0411\u0414 \u043d\u0438\u0436\u0435, \u043a\u0430\u043a \u0438 &#171;\u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c&#187;.<\/p>\n<h3>Tree<\/h3>\n<pre><code class=\"sql\">Tree as ( select  node_id, parent_node_id, node_name, parents, full_path, node_level, node_branch, cast(branch_through as char(2000)) as all_through from Branches where parent_node_id is null  union  select  Branches.node_id, Branches.parent_node_id, Branches.node_name, Branches.parents, Branches.full_path, Branches.node_level, Branches.node_branch, concat(prev.all_through, Branches.branch_through) from  Tree as prev inner join Branches on Branches.parent_node_id = prev.node_id ),<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043f\u043e\u043b\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u00ab\u0441\u043a\u0432\u043e\u0437\u043d\u044b\u043c\u0438 \u0432\u0435\u0442\u0432\u044f\u043c\u0438\u00bb <code>all_through<\/code><\/p>\n<p><em>\u041c\u044b \u043f\u043e\u0447\u0442\u0438 \u0443 \u0446\u0435\u043b\u0438!<\/em><\/p>\n<h3>FineTree<\/h3>\n<pre><code class=\"sql\">FineTree as ( select  tr.node_id, tr.parent_node_id, tr.node_name, tr.parents, tr.full_path, tr.node_level, concat(coalesce(parent.all_through, ''), tr.node_branch, tr.node_name) as fine_tree from  Tree as tr left join Tree as parent on parent.node_id = tr.parent_node_id order by tr.full_path )  select fine_tree from FineTree ;<\/code><\/pre>\n<p>\u0414\u043b\u0438\u043d\u0430 \u043f\u043e\u043b\u044f <code>fine_tree<\/code> \u0431\u0443\u0434\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 \u0442\u0435\u043c\u0438 \u0436\u0435 2000 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c 450 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 (4 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c + \u0434\u043e 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u043c\u044f \u0443\u0437\u043b\u0430), \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u043d\u0441\u0442\u0440\u043e\u0432.<\/p>\n<p><em>\u0412\u0443\u0430\u043b\u044f:<\/em><\/p>\n<pre><code>fine_tree                           | ------------------------------------+ desktop                             | \u2514\u2500\u2500 test                            |     \u251c\u2500\u2500 \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438                    |     \u2502   \u251c\u2500\u2500 1.jpg                   |     \u2502   \u251c\u2500\u2500 avatar.png      <\/code><\/pre>\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-374786","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/374786","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=374786"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/374786\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=374786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=374786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=374786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}