{"id":464468,"date":"2025-06-25T15:00:28","date_gmt":"2025-06-25T15:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464468"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464468","title":{"rendered":"<span>\u00abIT-\u041f\u043b\u0430\u043d\u0435\u0442\u0430 2025\u00bb: \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430 \u043f\u043e PostgreSQL<\/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>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0432\u043e\u0435 \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043c\u0435\u0436\u0434\u0443\u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0439 \u043e\u043b\u0438\u043c\u043f\u0438\u0430\u0434\u0435 \u00abIT-\u041f\u043b\u0430\u043d\u0435\u0442\u0430\u00bb.\u00a0 \u041a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u0433\u043e\u0434\u044b, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0441\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u043f\u043e SQL, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0442\u0440\u0435\u0445 \u044d\u0442\u0430\u043f\u043e\u0432: \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0443\u0440\u044b, \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043e\u043d\u043b\u0430\u0439\u043d, \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0447\u043d\u044b\u0439 \u0442\u0443\u0440.<\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0443\u0440\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0441\u0432\u044b\u0448\u0435 4 500 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 245 \u0431\u044b\u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u044b \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439. \u0412 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447 \u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0442\u0443\u0440\u043e\u0432. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 1. \u0421\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0439 \u041a\u0430\u0440\u043b\u0441\u043e\u043d<\/h2>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0435\u043d\u044c\u0435. \u041e\u043d \u043e\u0449\u0443\u0449\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u0434\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u044f\u0434 \u0441\u044a\u0435\u0434\u0430\u0435\u0442 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u043d\u043a\u0438 \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u0432 \u0434\u0435\u043d\u044c, \u0438 \u043f\u0440\u0438\u0442\u043e\u043c, \u0441\u044a\u0435\u0434\u0430\u0435\u0442 \u0437\u0430 \u044d\u0442\u0438 \u0434\u043d\u0438 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f.<\/p>\n<p>\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u0449\u0443\u0449\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434. \u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043d\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u0435\u043d.<\/p>\n<p>\u0412\u0435\u0441\u044c \u0433\u043e\u0434 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 jam, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u0441\u044a\u0435\u0434\u0430\u043b. \u0418\u043d\u043e\u0433\u0434\u0430 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043e\u0448\u0438\u0431\u0430\u043b\u0441\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0441\u044a\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u043d\u043a\u0438 \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438.<\/p>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<pre><code class=\"pgsql\">CREATE TABLE jam (    at date not null,     qty integer not null check (qty&gt;=0) );<\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0414\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO jam VALUES  ('2025-01-04',1),('2025-01-05',1),('2025-01-07',1), ('2025-01-08',2),('2025-01-09',2),('2025-01-10',1), ('2025-01-11',1),('2025-01-12',2),('2025-01-13',1), ('2025-01-14',1),('2025-01-15',1);<\/code><\/pre>\n<p>\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"pgsql\"> happydays  -----------          2 (1 row) <\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0435\u043b \u0432\u0430\u0440\u0435\u043d\u044c\u0435 3 \u0434\u043d\u044f \u043f\u043e\u0434\u0440\u044f\u0434 \u0431\u0435\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432, \u0438 \u0432 \u044d\u0442\u0438 \u0434\u043d\u0438 \u043e\u043d \u0441\u044a\u0435\u0434\u0430\u043b \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 4 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043d\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u0442\u0441\u044f \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043d\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u0435\u043d.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u044f\u0432\u043d\u043e \u043d\u0435 \u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0442\u0430\u043a \u0438 \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u043c.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435:<\/p>\n<ol>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430 \u043e\u0434\u043d\u0443 \u0434\u0430\u0442\u0443 (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0441 qty &gt; 0)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c qty = 0 (\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435 \u0435\u043b \u0432\u0430\u0440\u0435\u043d\u044c\u0435 \u0432 \u044d\u0442\u043e\u0442 \u0434\u0435\u043d\u044c, \u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b).<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432. \u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 RANGE \u0432\u043c\u0435\u0441\u0442\u043e ROWS \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438 \u0432 \u0434\u0430\u0442\u0430\u0445.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0434\u0430\u0442\u044b, \u0433\u0434\u0435 \u0431\u044b\u043b\u043e \u0441\u044a\u0435\u0434\u0435\u043d\u043e 0 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0434\u0430\u0442\u043e\u0439.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO jam VALUES('2025-01-04',1),('2025-01-05',1),('2025-01-07',1),                       ('2025-01-08',1),('2025-01-09',1),('2025-01-10',1),                       ('2025-01-08',1),('2025-01-09',0),('2025-01-10',1),                       ('2025-01-11',1),('2025-01-12',1),('2025-01-13',1),                       ('2025-01-11',0),('2025-01-12',1),('2025-01-13',0),                       ('2025-01-16',2),('2025-01-16',0),('2025-01-17',0),                       ('2025-01-17',1),('2025-01-18',1),('2025-01-19',2),                       ('2025-01-20',1),('2025-01-21',1),('2025-01-22',2),                       ('2025-01-23',1),('2025-01-25',6),('2025-01-26',1);<\/code><\/pre>\n<pre><code class=\"pgsql\">olymp=# select * from jam order by at;      at     | qty  ------------+-----  2025-01-04 |   1  2025-01-05 |   1  2025-01-07 |   1  2025-01-08 |   1  2025-01-08 |   1  2025-01-09 |   1  2025-01-09 |   0  2025-01-10 |   1  2025-01-10 |   1  2025-01-11 |   1  2025-01-11 |   0  2025-01-12 |   1  2025-01-12 |   1  2025-01-13 |   1  2025-01-13 |   0  2025-01-16 |   2  2025-01-16 |   0  2025-01-17 |   0  2025-01-17 |   1  2025-01-18 |   1  2025-01-19 |   2  2025-01-20 |   1  2025-01-21 |   1  2025-01-22 |   2  2025-01-23 |   1  2025-01-25 |   6  2025-01-26 |   1 (27 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_jam &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>\u0418\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0434\u043d\u0438 \u0441 qty=0 \u0438 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0434\u0430\u0442\u0430\u043c.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        SUM(qty) AS qty   FROM jam  GROUP BY at HAVING SUM(qty) &gt; 0<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | qty  ------------+-----  2025-01-04 |   1  2025-01-05 |   1  2025-01-07 |   1  2025-01-08 |   2  2025-01-09 |   1  2025-01-10 |   2  2025-01-11 |   1  2025-01-12 |   2  2025-01-13 |   1  2025-01-16 |   2  2025-01-17 |   1  2025-01-18 |   1  2025-01-19 |   2  2025-01-20 |   1  2025-01-21 |   1  2025-01-22 |   2  2025-01-23 |   1  2025-01-25 |   6  2025-01-26 |   1 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_courage \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u043d\u0438 \u0441 \u043f\u0440\u0438\u043b\u0438\u0432\u0430\u043c\u0438 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u00ab3 \u0434\u043d\u044f \u043f\u043e\u0434\u0440\u044f\u0434 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0431\u0430\u043d\u043e\u043a \u0437\u0430 \u044d\u0442\u043e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u00bb. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u043e\u043a\u043d\u043e\u043c, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u0435\u043d\u044c \u0438 \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c range \u043f\u043e \u0434\u0430\u0442\u0430\u043c, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c). \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u00a0 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 count(*)=3, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        CASE WHEN COUNT(*) over w = 3 AND SUM(qty) over w &gt; 3              THEN 1              ELSE 0          END AS is_courage   FROM daily_jam WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '2' DAY PRECEDING                 AND CURRENT ROW)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | is_courage  ------------+------------  2025-01-04 |          0  2025-01-05 |          0  2025-01-07 |          0  2025-01-08 |          0  2025-01-09 |          1  2025-01-10 |          1  2025-01-11 |          1  2025-01-12 |          1  2025-01-13 |          1  2025-01-16 |          0  2025-01-17 |          0  2025-01-18 |          1  2025-01-19 |          1  2025-01-20 |          1  2025-01-21 |          1  2025-01-22 |          1  2025-01-23 |          1  2025-01-25 |          0  2025-01-26 |          0 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_happy &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0435 \u0434\u043d\u0438. \u0414\u0435\u043d\u044c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0439, \u0435\u0441\u043b\u0438 \u0443 \u041a\u0430\u0440\u043b\u0441\u043e\u043d\u0430 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434 \u0431\u044b\u043b \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u0434\u043d\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        is_courage,        CASE WHEN SUM(is_courage) OVER w = 5              THEN 1              ELSE 0          END AS is_happy   FROM daily_courage WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '4' DAY PRECEDING                 AND CURRENT ROW)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | is_courage | is_happy  ------------+------------+----------  2025-01-04 |          0 |        0  2025-01-05 |          0 |        0  2025-01-07 |          0 |        0  2025-01-08 |          0 |        0  2025-01-09 |          1 |        0  2025-01-10 |          1 |        0  2025-01-11 |          1 |        0  2025-01-12 |          1 |        0  2025-01-13 |          1 |        1  2025-01-16 |          0 |        0  2025-01-17 |          0 |        0  2025-01-18 |          1 |        0  2025-01-19 |          1 |        0  2025-01-20 |          1 |        0  2025-01-21 |          1 |        0  2025-01-22 |          1 |        1  2025-01-23 |          1 |        1  2025-01-25 |          0 |        0  2025-01-26 |          0 |        0 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0445 \u0434\u043d\u0435\u0439.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">WITH daily_jam AS ( SELECT at AS at,        SUM(qty) AS qty   FROM jam  GROUP BY at HAVING SUM(qty) &gt; 0 ), daily_courage AS ( SELECT at AS at,        CASE WHEN COUNT(*) over w = 3 AND SUM(qty) over w &gt; 3              THEN 1              ELSE 0          END AS is_courage   FROM daily_jam WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '2' DAY PRECEDING                 AND CURRENT ROW) ), daily_happy AS ( SELECT at AS at,        CASE WHEN SUM(is_courage) OVER w = 5              THEN 1              ELSE 0          END AS is_happy   FROM daily_courage WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '4' DAY PRECEDING                AND CURRENT ROW) ) SELECT COALESCE(SUM(is_happy), 0) AS happydays   FROM daily_happy;<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\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<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> happydays  -----------          3 (1 row)<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u043e \u0441\u0434\u0432\u0438\u0433\u0430\u043c\u0438 \u043d\u0430 1\u20132 \u0434\u043d\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 LEAD (LAG) \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c (\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c) \u0441\u0442\u0440\u043e\u043a\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044f \u0441 \u0448\u0430\u0433\u043e\u043c 1 \u0434\u0435\u043d\u044c \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445:<\/p>\n<ol>\n<li>\n<p>\u041d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043d\u0438 \u0441 qty = 0.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u044f\u043b\u0430\u0441\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438 \u0432 \u0434\u0430\u0442\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u0434\u0435\u043d\u044c.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 2. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/h2>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL. \u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params:<\/p>\n<pre><code class=\"pgsql\">CREATE TABLE params (        parameter_name TEXT NOT NULL,        ts timestamp NOT NULL,        value  TEXT NULL,        PRIMARY KEY (parameter_name,ts));<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00e1\u044f \u043c\u0435\u0442\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c null \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00f3\u0439 \u043c\u0435\u0442\u043a\u043e\u0439.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u0442\u0430\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u0432\u0441\u0435.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0414\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO params (parameter_name, ts, value) VALUES ('max_connections', '2025-01-10 11:30', '500'),        ('max_connections', '2025-01-14 09:30', NULL),        ('work_mem', '2025-01-11 08:35', '8MB'),        ('work_mem', '2025-01-17 14:00', NULL),        ('shared_buffers', '2025-01-14 10:00', '20000'),        ('shared_buffers', '2025-01-15 07:40', NULL),        ('temp_buffers', '2025-01-22 11:15', '2000'),        ('maintenance_work_mem', '2025-01-19 10:20', '1000'),        ('maintenance_work_mem', '2025-01-19 13:26', null),        ('max_worker_processes', '2025-01-09 00:30', '16'),        ('max_worker_processes', '2025-01-14 08:30', null);<\/code><\/pre>\n<p>\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"pgsql\">      ts_start       |       ts_end        | parameters  ---------------------+---------------------+------------  2025-01-11 08:35:00 | 2025-01-14 08:30:00 |          3 (1 row)<\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b, \u0433\u0434\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 (\u043d\u0435 NULL) \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c 2 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u043f\u043e\u043b\u0443\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 [start, end).<\/p>\n<\/li>\n<li>\n<p>null-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u043a\u0442\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0431\u0440\u043e\u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430 \u0432\u0435\u0441\u044c \u043f\u0435\u0440\u0438\u043e\u0434 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u0442\u0435\u043c \u0436\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b (\u0431\u0435\u0437 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0434\u0430\u0442\u044b) \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430\u043c\u0438 \u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430\u043c\u0438 \u0432 PostgreSQL. \u0412 2024 \u0433\u043e\u0434\u0443 \u043c\u044b \u0443\u0436\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u00ab<a href=\"https:\/\/habr.com\/ru\/companies\/postgrespro\/articles\/808211\/\" rel=\"noopener noreferrer nofollow\">\u041c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u044b\u0439 \u0426\u0435\u0440\u0431\u0435\u0440<\/a>\u00bb. \u0414\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u0421\u0443\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0432\u0441\u0435 \u043f\u0435\u0440\u0438\u043e\u0434\u044b, \u043a\u043e\u0433\u0434\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u043c\u0435\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0417\u0430\u0442\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u2014 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b. \u042d\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0435\u0440\u0438\u043e\u0434. \u0412 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u043a\u043e\u043d\u043a\u0443\u0440\u0441\u0430\u043d\u0442\u043e\u0432 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438\u0441\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u0430\u0442\u043e\u0439, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0430\u0442\u043e\u0439 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0434\u0430\u0442\u043e\u0439 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u0438 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0438\u0445, \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438 \u0438 \u0438\u0445 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u041c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0442\u043e\u0447\u043d\u044b\u0439 \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u0443\u0447\u0435\u0442 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430\u043c\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0438\u0441\u0442\u043e\u0442\u0435 \u2014 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u043a\u0430\u043a \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0438 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0440\u0443\u0447\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0433\u0440\u0430\u043d\u0438\u0446 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0438 \u0438\u0445 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0439. <\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u0442\u0430\u043b\u043e\u043d\u043e\u0432 \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u0430\u043d\u043d\u044b\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043a\u0440\u0438\u043f\u0442<\/p>\n<pre><code class=\"pgsql\">INSERT INTO params  (parameter_name, ts, value) VALUES ('max_connections', '2025-01-10 11:30', '500'),        ('max_connections', '2025-01-11 12:30', NULL),        ('max_connections', '2025-01-11 15:30', '500'),        ('max_connections', '2025-01-12 12:30', NULL),        ('max_connections', '2025-01-12 15:30', '500'),        ('work_mem', '2025-01-10 11:30', '8MB'),        ('work_mem', '2025-01-12 14:00', '16MB'),        ('max_connections', '2025-01-12 14:00', 1000),        ('max_connections', '2025-01-17 12:30', NULL),        ('shared_buffers', '2025-01-12 12:30', NULL),        ('shared_buffers', '2025-01-12 13:30', '20000'),        ('shared_buffers', '2025-01-14 10:00', NULL),        ('shared_buffers', '2025-01-15 07:40', NULL),        ('temp_buffers', '2025-01-09 10:20', '2000'),        ('temp_buffers', '2025-01-11 11:30', null),        ('temp_buffers', '2025-01-12 12:30', '1500'),        ('temp_buffers', '2025-01-14 03:15', null),        ('maintenance_work_mem', '2025-01-09 10:20','1000'),        ('maintenance_work_mem', '2025-01-10 13:26', null),        ('maintenance_work_mem', '2025-01-12 12:30', null),        ('maintenance_work_mem', '2025-01-12 14:30', '1500'),        ('maintenance_work_mem', '2025-01-15 14:30', null),        ('max_worker_processes', '2025-01-08 00:30', '16'),        ('max_worker_processes', '2025-01-12 14:00', null);<\/code><\/pre>\n<pre><code class=\"pgsql\">olymp=# select * from params order by 1,2;     parameter_name    |         ts          | value  ----------------------+---------------------+-------  maintenance_work_mem | 2025-01-09 10:20:00 | 1000  maintenance_work_mem | 2025-01-10 13:26:00 |   maintenance_work_mem | 2025-01-12 12:30:00 |   maintenance_work_mem | 2025-01-12 14:30:00 | 1500  maintenance_work_mem | 2025-01-15 14:30:00 |   max_connections      | 2025-01-10 11:30:00 | 500  max_connections      | 2025-01-11 12:30:00 |   max_connections      | 2025-01-11 15:30:00 | 500  max_connections      | 2025-01-12 12:30:00 |   max_connections      | 2025-01-12 14:00:00 | 1000  max_connections      | 2025-01-12 15:30:00 | 500  max_connections      | 2025-01-17 12:30:00 |   max_worker_processes | 2025-01-08 00:30:00 | 16  max_worker_processes | 2025-01-12 14:00:00 |   shared_buffers       | 2025-01-12 12:30:00 |   shared_buffers       | 2025-01-12 13:30:00 | 20000  shared_buffers       | 2025-01-14 10:00:00 |   shared_buffers       | 2025-01-15 07:40:00 |   temp_buffers         | 2025-01-09 10:20:00 | 2000  temp_buffers         | 2025-01-11 11:30:00 |   temp_buffers         | 2025-01-12 12:30:00 | 1500  temp_buffers         | 2025-01-14 03:15:00 |   work_mem             | 2025-01-10 11:30:00 | 8MB  work_mem             | 2025-01-12 14:00:00 | 16MB (24 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 P \u2014 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<pre><code class=\"pgsql\">select parameter_name,        ts as ts_start,        lead(ts) over (partition by parameter_name order by ts) as ts_end,        value   from params<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">    parameter_name    |      ts_start       |       ts_end        | value  ----------------------+---------------------+---------------------+-------  maintenance_work_mem | 2025-01-09 10:20:00 | 2025-01-10 13:26:00 | 1000  maintenance_work_mem | 2025-01-10 13:26:00 | 2025-01-12 12:30:00 |   maintenance_work_mem | 2025-01-12 12:30:00 | 2025-01-12 14:30:00 |   maintenance_work_mem | 2025-01-12 14:30:00 | 2025-01-15 14:30:00 | 1500  maintenance_work_mem | 2025-01-15 14:30:00 |                     |   max_connections      | 2025-01-10 11:30:00 | 2025-01-11 12:30:00 | 500  max_connections      | 2025-01-11 12:30:00 | 2025-01-11 15:30:00 |   max_connections      | 2025-01-11 15:30:00 | 2025-01-12 12:30:00 | 500  max_connections      | 2025-01-12 12:30:00 | 2025-01-12 14:00:00 |   max_connections      | 2025-01-12 14:00:00 | 2025-01-12 15:30:00 | 1000  max_connections      | 2025-01-12 15:30:00 | 2025-01-17 12:30:00 | 500  max_connections      | 2025-01-17 12:30:00 |                     |   max_worker_processes | 2025-01-08 00:30:00 | 2025-01-12 14:00:00 | 16  max_worker_processes | 2025-01-12 14:00:00 |                     |   shared_buffers       | 2025-01-12 12:30:00 | 2025-01-12 13:30:00 |   shared_buffers       | 2025-01-12 13:30:00 | 2025-01-14 10:00:00 | 20000  shared_buffers       | 2025-01-14 10:00:00 | 2025-01-15 07:40:00 |   shared_buffers       | 2025-01-15 07:40:00 |                     |   temp_buffers         | 2025-01-09 10:20:00 | 2025-01-11 11:30:00 | 2000  temp_buffers         | 2025-01-11 11:30:00 | 2025-01-12 12:30:00 |   temp_buffers         | 2025-01-12 12:30:00 | 2025-01-14 03:15:00 | 1500  temp_buffers         | 2025-01-14 03:15:00 |                     |   work_mem             | 2025-01-10 11:30:00 | 2025-01-12 14:00:00 | 8MB  work_mem             | 2025-01-12 14:00:00 |                     | 16MB (24 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 PS\u00a0\u2014 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b, \u0433\u0434\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0435 null, \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0437 \u043d\u0438\u0445 \u0442\u0438\u043f-\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d.<\/p>\n<pre><code class=\"pgsql\">select parameter_name,        tsrange(ts_start, ts_end) as ParameterSetRange,        value   from P  where value is not null<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">    parameter_name    |               parametersetrange               | value  ----------------------+-----------------------------------------------+-------  maintenance_work_mem | [\"2025-01-09 10:20:00\",\"2025-01-10 13:26:00\") | 1000  maintenance_work_mem | [\"2025-01-12 14:30:00\",\"2025-01-15 14:30:00\") | 1500  max_connections      | [\"2025-01-10 11:30:00\",\"2025-01-11 12:30:00\") | 500  max_connections      | [\"2025-01-11 15:30:00\",\"2025-01-12 12:30:00\") | 500  max_connections      | [\"2025-01-12 14:00:00\",\"2025-01-12 15:30:00\") | 1000  max_connections      | [\"2025-01-12 15:30:00\",\"2025-01-17 12:30:00\") | 500  max_worker_processes | [\"2025-01-08 00:30:00\",\"2025-01-12 14:00:00\") | 16  shared_buffers       | [\"2025-01-12 13:30:00\",\"2025-01-14 10:00:00\") | 20000  temp_buffers         | [\"2025-01-09 10:20:00\",\"2025-01-11 11:30:00\") | 2000  temp_buffers         | [\"2025-01-12 12:30:00\",\"2025-01-14 03:15:00\") | 1500  work_mem             | [\"2025-01-10 11:30:00\",\"2025-01-12 14:00:00\") | 8MB  work_mem             | [\"2025-01-12 14:00:00\",)                      | 16MB (12 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 PAS \u2014 \u0441\u0442\u0440\u043e\u0438\u043c \u0442\u0438\u043f-\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u00ab\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435\u00bb \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"pgsql\">select tsrange(ts, lead(ts) over (order by ts)) as ParameterSetRange   from params  where ts is not null<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">               parametersetrange                -----------------------------------------------  empty  empty  empty  empty  empty  empty  empty  [\"2025-01-08 00:30:00\",\"2025-01-09 10:20:00\")  [\"2025-01-09 10:20:00\",\"2025-01-10 11:30:00\")  [\"2025-01-10 11:30:00\",\"2025-01-10 13:26:00\")  [\"2025-01-10 13:26:00\",\"2025-01-11 11:30:00\")  [\"2025-01-11 11:30:00\",\"2025-01-11 12:30:00\")  [\"2025-01-11 12:30:00\",\"2025-01-11 15:30:00\")  [\"2025-01-11 15:30:00\",\"2025-01-12 12:30:00\")  [\"2025-01-12 12:30:00\",\"2025-01-12 13:30:00\")  [\"2025-01-12 13:30:00\",\"2025-01-12 14:00:00\")  [\"2025-01-12 14:00:00\",\"2025-01-12 14:30:00\")  [\"2025-01-12 14:30:00\",\"2025-01-12 15:30:00\")  [\"2025-01-12 15:30:00\",\"2025-01-14 03:15:00\")  [\"2025-01-14 03:15:00\",\"2025-01-14 10:00:00\")  [\"2025-01-14 10:00:00\",\"2025-01-15 07:40:00\")  [\"2025-01-15 07:40:00\",\"2025-01-15 14:30:00\")  [\"2025-01-15 14:30:00\",\"2025-01-17 12:30:00\")  [\"2025-01-17 12:30:00\",) (24 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 RES &#8212; \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u043c\u00a0 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441 \u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e range_agg(). \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0432\u044b\u0432\u043e\u0434 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<pre><code class=\"pgsql\">select range_agg (ParameterSetRange) as ParameterSetRange,        cnt_parameter   from (select PAS.ParameterSetRange,                count(parameter_name) as cnt_parameter           from PS,        PAS          where not isempty (PS.ParameterSetRange*PAS.ParameterSetRange)    group by PAS.ParameterSetRange) group by cnt_parameter <\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">\\x -[ RECORD 1 ]-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ parametersetrange | {[\"2025-01-08 00:30:00\",\"2025-01-09 10:20:00\"),[\"2025-01-17 12:30:00\",)} cnt_parameter     | 1 -[ RECORD 2 ]-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ parametersetrange | {[\"2025-01-09 10:20:00\",\"2025-01-10 11:30:00\"),[\"2025-01-11 11:30:00\",\"2025-01-11 12:30:00\"),[\"2025-01-11 15:30:00\",\"2025-01-12 13:30:00\"),[\"2025-01-14 10:00:00\",\"2025-01-15 14:30:00\")} cnt_parameter     | 3 -[ RECORD 3 ]-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ parametersetrange | {[\"2025-01-10 11:30:00\",\"2025-01-10 13:26:00\"),[\"2025-01-12 14:30:00\",\"2025-01-14 03:15:00\")} cnt_parameter     | 5 -[ RECORD 4 ]-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ parametersetrange | {[\"2025-01-10 13:26:00\",\"2025-01-11 11:30:00\"),[\"2025-01-12 13:30:00\",\"2025-01-12 14:30:00\"),[\"2025-01-14 03:15:00\",\"2025-01-14 10:00:00\")} cnt_parameter     | 4 -[ RECORD 5 ]-----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ parametersetrange | {[\"2025-01-11 12:30:00\",\"2025-01-11 15:30:00\"),[\"2025-01-15 14:30:00\",\"2025-01-17 12:30:00\")} cnt_parameter     | 2<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0432\u044b\u0432\u043e\u0434 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 2-\u0445 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445. \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u0443\u043b\u044c\u0442\u0438\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e unnest().  \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0447\u0430\u043b\u043e, \u043a\u043e\u043d\u0435\u0446 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430.<\/p>\n<pre><code class=\"pgsql\">select lower(ParameterSetRange) as ts_start,        upper(ParameterSetRange) as ts_end,    cnt_parameter as parameters  from (select unnest(ParameterSetRange) as ParameterSetRange,               cnt_parameter          from Res         where cnt_parameter =               (select max(cnt_parameter)                 from Res                 where cnt_parameter != 1)              ) order by ParameterSetRange<\/code><\/pre>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">      ts_start       |       ts_end        | parameters  ---------------------+---------------------+------------  2025-01-10 11:30:00 | 2025-01-10 13:26:00 |          5  2025-01-12 14:30:00 | 2025-01-14 03:15:00 |          5 (2 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">with  P as (   select parameter_name,          ts as ts_start,          lead(ts) over (partition by parameter_name order by ts) as ts_end,          value     from params ), PS as (   select parameter_name,          tsrange(ts_start, ts_end) as ParameterSetRange,          value     from P    where value is not null   ), PAS as (    select tsrange(ts, lead(ts) over (order by ts)) as ParameterSetRange      from params     where ts is not null ), Res as (    select range_agg (ParameterSetRange) as ParameterSetRange,           cnt_parameter      from (select PAS.ParameterSetRange,               count(parameter_name) as cnt_parameter         from PS,          PAS        where not isempty (PS.ParameterSetRange * PAS.ParameterSetRange)        group by PAS.ParameterSetRange)    group by cnt_parameter )    select lower(ParameterSetRange) as ts_start,       upper(ParameterSetRange) as ts_end,       cnt_parameter parameters      from (select unnest(ParameterSetRange) as ParameterSetRange,                   cnt_parameter           from Res         where cnt_parameter = (select max(cnt_parameter)                                       from Res                                      where cnt_parameter != 1))    order by ParameterSetRange;<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0423\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438:<\/p>\n<ol>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 LEAD (LAG) \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c (\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c) \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0434\u0430\u0442\u0430, \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0434\u0430\u0442\u0430 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0438\u043b\u0438 \u0441\u0442\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0430\u0442\u043e\u0439 \u0438\u0437 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 3. \u0418\u0422-\u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044f<\/h2>\n<p>\u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0441\u0430\u043c\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0439, \u0432\u0441\u0435\u0433\u043e 2 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0438 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u041a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u00ab\u0421\u0423\u0411\u0414 \u0438\u043d\u0436\u0438\u043d\u0438\u0440\u0438\u043d\u0433\u00bb \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u0435\u0436\u0435\u0433\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044e. \u0423\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438 \u043f\u043b\u0430\u0442\u043d\u043e\u0435. \u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u0431\u0438\u043b\u0435\u0442\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>Standard \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e 2000 \u0440 \u0437\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>Allinclusive \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e 4000 \u0440 \u0437\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>Dual \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e 6000 \u0440 \u0437\u0430 \u0434\u0432\u0443\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u0430\u0431\u043b\u0438\u0446\u0443 tickets \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u0438\u0438 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430\u043c\u0438.<\/p>\n<pre><code class=\"pgsql\">CREATE TABLE tickets (Id_Ticket int,      -- \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0431\u0438\u043b\u0435\u0442\u0430  TicketDate date,    -- \u0434\u0430\u0442\u0430 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u0438\u044f  TicketType text CHECK (TicketType IN ('Standard', 'Allinclusive', 'Dual')),  Person text,        -- \u0424\u0418\u041e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430  PRIMARY KEY (Id_Ticket, Person),  UNIQUE (TicketDate, Person, TicketType) );<\/code><\/pre>\n<p>\u0427\u0430\u0441\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a\u043e\u0439 \u0431\u0438\u043b\u0435\u0442 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043c\u0435\u043d\u044f\u043b\u0438 \u0441\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u0444\u0430\u043a\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0431\u0438\u043b\u0435\u0442\u0430 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043e \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u0438\u0438 \u0431\u0438\u043b\u0435\u0442\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u043c\u043e\u0433 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0431\u0438\u043b\u0435\u0442\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432 \u0434\u0435\u043d\u044c. \u0421\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438 \u043d\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0445 \u0442\u0451\u0437\u043e\u043a, \u0442\u043e \u0435\u0441\u0442\u044c \u0424\u0418\u041e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0435\u0439 \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u0438\u044f \u0440\u0435\u0448\u0438\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0432\u0435\u0440\u043a\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 \u0441\u0443\u043c\u043c\u0443 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0443\u0440\u043e\u0432\u043d\u044e;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432, \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 \u043e\u0431\u0449\u0443\u044e \u0441\u0443\u043c\u043c\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c:<\/p>\n<ol>\n<li>\n<p>\u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0431\u0438\u043b\u0435\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u0430\u0442\u0435 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u0438\u044f \u0431\u0438\u043b\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0434\u0430\u0442\u0443 \u043e\u0434\u043d\u0438\u043c \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u043c \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432, \u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0431\u0438\u043b\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f (\u0443\u0440\u043e\u0432\u043d\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044f: Dual, Allinclusive, Standard);<\/p>\n<\/li>\n<li>\n<p>\u0411\u0438\u043b\u0435\u0442 \u0443\u0440\u043e\u0432\u043d\u044f Dual \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u044e \u0438\u0434\u0443\u0442 \u043e\u0431\u0430 \u0432\u043d\u0435\u0441\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0435\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (\u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043f\u043e\u0437\u0436\u0435 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u043b \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0438\u043b\u0435\u0442) \u0431\u0438\u043b\u0435\u0442 Dual \u0430\u043d\u043d\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u043f\u043e \u0434\u0430\u0442\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0431\u0438\u043b\u0435\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0414\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO tickets VALUES (1,'2025.02.18','Allinclusive','\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (2,'2025.02.18','Dual', '\u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (2,'2025.02.18','Dual', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (3,'2025.02.17','Allinclusive', '\u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447'), (4,'2025.02.15','Standard', '\u0417\u0430\u0439\u0446\u0435\u0432 \u0421\u0435\u0440\u0433\u0435\u0439 \u041f\u0435\u0442\u0440\u043e\u0432\u0438\u0447');<\/code><\/pre>\n<p>\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"pgsql\">  tickettype  | tickets | participants |  sum   --------------+---------+--------------+-------  Allinclusive |       1 |            1 |  4000  Dual         |       1 |            2 |  6000  Standard     |       1 |            1 |  2000               |       3 |            4 | 12000 (4 rows)<\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0434\u0430\u0442\u044b. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0434\u0430\u0442\u0430 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u043d\u0438\u044f \u0431\u0438\u043b\u0435\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0442\u0438\u043f\u0430 \u0431\u0438\u043b\u0435\u0442\u0430 \u043f\u0440\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0434\u0430\u0442\u0430\u0445:<\/p>\n<ul>\n<li>\n<p>Dual (\u0432\u044b\u0441\u0448\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442);<\/p>\n<\/li>\n<li>\n<p>Allinclusive;<\/p>\n<\/li>\n<li>\n<p>Standard (\u043d\u0438\u0437\u0448\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442);<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0431\u0438\u043b\u0435\u0442\u043e\u0432 Dual:<\/p>\n<ul>\n<li>\n<p>\u0411\u0438\u043b\u0435\u0442 Dual \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c id_ticket.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0438\u043b\u0435\u0442 Dual \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043e\u0431\u0430 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 \u044d\u0442\u043e\u043c \u0431\u0438\u043b\u0435\u0442\u0435, \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0438\u0445 \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u0431\u0438\u043b\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043f\u043e\u0437\u0436\u0435 \u043a\u0443\u043f\u0438\u043b \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0438\u043b\u0435\u0442, \u0431\u0438\u043b\u0435\u0442 Dual \u0430\u043d\u043d\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0431\u0438\u043b\u0435\u0442\u0443.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e \u0442\u0438\u043f\u0430\u043c \u0431\u0438\u043b\u0435\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>Standard:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u043b\u044e\u0434\u0435\u0439 \u0441 \u0431\u0438\u043b\u0435\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0430 = \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u00d7 2000 \u0440\u0443\u0431.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Allinclusive:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u043b\u044e\u0434\u0435\u0439 \u0441 \u0431\u0438\u043b\u0435\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0430 = \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u00d7 4000 \u0440\u0443\u0431.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Dual:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 = \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u00d7 2.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0430 = \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u00d7 6000 \u0440\u0443\u0431.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432 = \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0438\u043f\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 = \u0441\u0443\u043c\u043c\u0430 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0438\u043f\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0430\u044f \u0441\u0443\u043c\u043c\u0430 = \u0441\u0443\u043c\u043c\u0430 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0438\u043f\u0430\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0423\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f \u0431\u0438\u043b\u0435\u0442\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0442\u044b \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u044f\u0432\u043d\u043e \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u043d\u043e \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u0438\u043b\u0435\u0442\u0430 \u0430\u043d\u043d\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f Dual-\u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u0431\u043e\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043a\u0443\u043f\u043a\u0438).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0435 \u0431\u0438\u043b\u0435\u0442 \u0443\u0440\u043e\u0432\u043d\u044f dual, \u0438\u0437 \u0437\u0430 \u0447\u0435\u0433\u043e \u0432 \u0440\u0430\u0441\u0447\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0440\u0430\u043d\u0435\u0435 \u043a\u0443\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u0431\u0438\u043b\u0435\u0442 \u0443\u0440\u043e\u0432\u043d\u044f dual.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043a\u0440\u0438\u043f\u0442<\/p>\n<pre><code class=\"pgsql\">INSERT INTO tickets VALUES (1,'2025.02.18','Standard','\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (2,'2025.02.18','Dual', '\u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (2,'2025.02.18','Dual', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (3,'2025.02.19','Allinclusive', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (4,'2025.02.15','Allinclusive', '\u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (5,'2025.02.20','Standard', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (6,'2025.02.17','Dual', '\u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447'), (6,'2025.02.17','Dual', '\u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447');<\/code><\/pre>\n<pre><code class=\"pgsql\">olymp=# select * from tickets t order by 2,1;   id_ticket | ticketdate |  tickettype  |         person           -----------+------------+--------------+-------------------------          4 | 2025-02-15 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          6 | 2025-02-17 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447          6 | 2025-02-17 | Dual         | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          1 | 2025-02-18 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          2 | 2025-02-18 | Dual         | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          2 | 2025-02-18 | Dual         | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          3 | 2025-02-19 | Allinclusive | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447          5 | 2025-02-20 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 (8 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 grp &#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0431\u0438\u043b\u0435\u0442\u0430\u043c. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0438\u043b\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430. \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0430\u0442\u0443 \u0431\u0438\u043b\u0435\u0442\u0430, \u0442\u0438\u043f \u0431\u0438\u043b\u0435\u0442\u0430 \u0438 \u0435\u0433\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c, \u0434\u0432\u0443\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0431\u0438\u043b\u0435\u0442\u0430 dual \u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0430 \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0431\u0438\u043b\u0435\u0442\u0430.<\/p>\n<pre><code class=\"pgsql\">SELECT id_ticket,         min(ticketdate) ticketdate,         min(tickettype) tickettype,        min(person) person1,         max(person) person2,         count(*) qty,        CASE min(tickettype) WHEN 'Standard' THEN 2000                             WHEN 'Allinclusive' THEN 4000                              ELSE 6000 END AS amount   FROM tickets t   GROUP BY id_ticket<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">  id_ticket | ticketdate |  tickettype  |         person1         |       person2        | qty | amount  -----------+------------+--------------+-------------------------+----------------------+-----+--------          3 | 2025-02-19 | Allinclusive | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000          5 | 2025-02-20 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000          4 | 2025-02-15 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000          6 | 2025-02-17 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000          2 | 2025-02-18 | Dual         | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000          1 | 2025-02-18 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 (6 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 t \u2014 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0438\u043b\u0435\u0442\u043e\u0432. \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e \u0434\u0430\u0442\u0435, \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0431\u0438\u043b\u0435\u0442\u0443.<\/p>\n<pre><code class=\"pgsql\">SELECT ticketdate,         tickettype,         person1,         person2,         qty,         amount,        row_number() OVER (ORDER BY ticketdate DESC, amount DESC) as p   FROM grp<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> ticketdate |  tickettype  |         person1         |       person2        | qty | amount | p  ------------+--------------+-------------------------+----------------------+-----+--------+---  2025-02-20 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 | 1  2025-02-19 | Allinclusive | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 | 2  2025-02-18 | Dual         | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 | 3  2025-02-18 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 | 4  2025-02-17 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 | 5  2025-02-15 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 | 6 (6 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 r \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0431\u0438\u043b\u0435\u0442\u0430. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u0431\u0438\u043b\u0435\u0442\u0430. \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0431\u0438\u043b\u0435\u0442\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0442\u0435\u0445, \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0449\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0438\u043b\u0435\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u2018A\u2019 (Approved), \u2018R\u2019 (Rejected) \u0438\u043b\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c null, \u043f\u043e\u043a\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d. \u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e, \u043f\u043e\u043a\u0430 \u0441\u0442\u0430\u0442\u0443\u0441\u044b \u0432\u0441\u0435\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b.<\/p>\n<pre><code class=\"pgsql\">SELECT p,         tickettype,         person1,         person2,         qty,         amount,         NULL::text status  FROM t UNION ALL   (WITH rr AS (SELECT * FROM r),          top AS (             SELECT * FROM rr              WHERE status IS NULL              ORDER BY p              LIMIT 1         )    SELECT t.p,            t.tickettype,            t.person1,            t.person2,            t.qty,            t.amount,           CASE WHEN t.p = top.p                THEN 'A' -- approved                WHEN t.person1 = top.person1                   OR t.person1 = top.person2                   OR t.person2 = top.person1                   OR t.person2 = top.person2                THEN 'R' -- rejected                ELSE NULL -- \u043f\u043e\u043a\u0430 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e             END      FROM t      JOIN rr ON t.p = rr.p     CROSS JOIN top     WHERE rr.status IS NULL   )<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> p |  tickettype  |         person1         |       person2        | qty | amount | status  ---+--------------+-------------------------+----------------------+-----+--------+-------  1 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 |   2 | Allinclusive | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 |   3 | Dual         | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 |   4 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 |   5 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 |   6 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 |   1 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 | A  2 | Allinclusive | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 | R  3 | Dual         | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 | R  4 | Standard     | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 | R  5 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 |   6 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 |   5 | Dual         | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 | A  6 | Allinclusive | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   4000 | R (14 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 approved \u2014 \u043e\u0442\u0431\u043e\u0440 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043b\u0435\u0442\u043e\u0432. \u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043b\u0435\u0442\u044b \u0441\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c Approved.<\/p>\n<pre><code class=\"pgsql\">SELECT *   FROM t  WHERE p IN (SELECT p                FROM r               WHERE status = 'A')<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> ticketdate | tickettype |         person1         |       person2        | qty | amount | p  ------------+------------+-------------------------+----------------------+-----+--------+--  2025-02-20 | Standard   | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447    | \u0418\u0432\u0430\u043d\u043e\u0432 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   1 |   2000 | 1  2025-02-17 | Dual       | \u041a\u0443\u0437\u043d\u0435\u0446\u043e\u0432 \u041f\u0435\u0442\u0440 \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 | \u041f\u043e\u043f\u043e\u0432 \u0424\u0435\u0434\u043e\u0440 \u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447 |   2 |   6000 | 5 (2 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 &#8212; \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0442\u0438\u043f\u0430\u043c \u0431\u0438\u043b\u0435\u0442\u043e\u0432; \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0442\u0438\u043f\u043e\u0432 \u0431\u0438\u043b\u0435\u0442\u043e\u0432 \u043d\u0435\u0442, \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0431\u0438\u043b\u0435\u0442\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043b\u0435\u0442\u043e\u0432, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 \u043e\u0431\u0449\u0443\u044e \u0441\u0443\u043c\u043c\u0443. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e grouping sets.<\/p>\n<pre><code class=\"pgsql\">SELECT tickettype,         count(*) AS tickets,         sum(qty) participants,         sum(amount) AS sum   FROM approved  GROUP BY GROUPING SETS (tickettype,())  order by tickettype;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> tickettype | tickets | participants | sum   ------------+---------+--------------+------  Dual       |       1 |            2 | 6000  Standard   |       1 |            1 | 2000             |       2 |            3 | 8000 (3 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">WITH RECURSIVE grp AS ( SELECT id_ticket,         min(ticketdate) ticketdate,         min(tickettype) tickettype,        min(person) person1,         max(person) person2,         count(*) qty,        CASE min(tickettype) WHEN 'Standard' THEN 2000                              WHEN 'Allinclusive' THEN 4000                              ELSE 6000        END AS amount   FROM tickets t  GROUP BY id_ticket ), t AS (   SELECT ticketdate,           tickettype,           person1,           person2,           qty,           amount,          row_number() OVER (ORDER BY ticketdate DESC, amount DESC) p     FROM grp ), r AS (   SELECT p,           tickettype,           person1,           person2,           qty,           amount,           NULL::text status     FROM t    UNION ALL   (     WITH rr AS (SELECT * FROM r),           top AS (              SELECT *                 FROM rr               WHERE status IS NULL               ORDER BY p               LIMIT 1          )    SELECT t.p,            t.tickettype,            t.person1,            t.person2,            t.qty,            t.amount,           CASE WHEN t.p = top.p                THEN 'A' -- approved                WHEN t.person1 = top.person1                   OR t.person1 = top.person2                   OR t.person2 = top.person1                   OR t.person2 = top.person2                THEN 'R' -- rejected                ELSE NULL -- \u043f\u043e\u043a\u0430 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e             END      FROM t      JOIN rr ON t.p = rr.p     CROSS JOIN top     WHERE rr.status IS NULL     ) ), approved AS (      SELECT *        FROM t       WHERE p IN (SELECT p                     FROM r                    WHERE status = 'A'    ) ) SELECT tickettype,         count(*) AS tickets,         sum(qty) participants,         sum(amount) AS sum   FROM approved  GROUP BY GROUPING SETS (tickettype,())  order by tickettype;<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 4. \u0418\u0433\u0440\u0430 \u00ab\u0411\u044b\u043a\u0438 \u0438 \u043a\u043e\u0440\u043e\u0432\u044b\u00bb<\/h2>\n<p><a class=\"anchor\" name=\"%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0\" id=\"\u041f\u0440\u0430\u0432\u0438\u043b\u0430\"><\/a><\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 4 \u0438 5 \u2014 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0438\u0433\u0440\u0443 \u00ab\u0411\u044b\u043a\u0438 \u0438 \u043a\u043e\u0440\u043e\u0432\u044b\u00bb.<\/p>\n<h3>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b<\/h3>\n<p>\u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u0433\u0440\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u0434\u0432\u0443\u0445 \u0438\u0433\u0440\u043e\u043a\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0438\u0433\u0440\u043e\u043a\u043e\u0432 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043d\u043e\u0435 4-\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0432 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f (0..9, A, B, C, D, E, F). \u0418\u0433\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0433\u0440\u0443 \u043f\u043e \u0436\u0440\u0435\u0431\u0438\u044e, \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u043e\u043f\u044b\u0442\u043a\u0443 \u043e\u0442\u0433\u0430\u0434\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e. \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u2014 \u044d\u0442\u043e 4-\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0446\u0438\u0444\u0440\u0430\u043c\u0438, \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c\u043e\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a\u0443. \u041f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440 \u0443\u0433\u0430\u0434\u0430\u043d\u043e \u0431\u0435\u0437 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441 \u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u0432 \u0442\u0430\u0439\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb) \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u0430\u0434\u0430\u043d\u043e \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0442\u0430\u0439\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb).<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>\u041f\u0443\u0441\u0442\u044c \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e \u0442\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u00ab32F9\u00bb.<\/p>\n<p>\u041f\u043e\u043f\u044b\u0442\u043a\u0430: \u00ab23F0\u00bb.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \u0434\u0432\u0435 \u00ab\u043a\u043e\u0440\u043e\u0432\u044b\u00bb (\u0434\u0432\u0435 \u0446\u0438\u0444\u0440\u044b: 2 \u0438 3 \u0443\u0433\u0430\u0434\u0430\u043d\u044b \u043d\u0430 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445) \u0438 \u043e\u0434\u0438\u043d \u00ab\u0431\u044b\u043a\u00bb (\u043e\u0434\u043d\u0430 \u0446\u0438\u0444\u0440\u0430 F \u0443\u0433\u0430\u0434\u0430\u043d\u0430 \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438).<\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 4-\u0439 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0412\u0430\u043c \u0434\u0430\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u0442\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0445\u043e\u0434\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u0438 \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043f\u0435\u0440\u0435\u0434 \u0431\u0443\u043a\u0432\u043e\u0439 B, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u2014 \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e \u043f\u0435\u0440\u0435\u0434 \u0431\u0443\u043a\u0432\u043e\u0439 C. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0442\u0430\u0439\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 32F9 \u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 23F0 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c 1B2C. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0445\u043e\u0434\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0445\u043e\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0434\u043e\u043f\u0438\u0441\u0430\u043d \u043e\u0442\u0432\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0445\u043e\u0434\u043e\u0432 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0446\u0438\u0444\u0440\u0430\u043c\u0438, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438. \u0421\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u044b\u043c \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u0441 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0446\u0438\u0444\u0440\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u044d\u0442\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u044b, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 error \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u0412\u0441\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u043a\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 bulls.game.<\/p>\n<p>\u0421\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 bulls.secretcode.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"pgsql\">set bulls.game = '56F8,9D13,3426,25b3,6D9A,3029'; set bulls.secretcode = '3D29';<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/p>\n<pre><code class=\"pgsql\">                          gameparty                           -------------------------------------------------------------  56F8 0B0C,9D13 1B2C,3426 2B0C,25B3 0B2C,6D9A 1B1C,3029 3B0C (1 row)<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0447\u0438\u0441\u043b\u0435 5 \u0446\u0438\u0444\u0440.<\/p>\n<pre><code class=\"pgsql\">set bulls.game = '56F8,9D13,3426F,25B3,6D9A,3029'; set bulls.secretcode = '3D29';<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/p>\n<pre><code class=\"pgsql\"> gameparty  -----------  error (1 row)<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u0421\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 4-\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0447\u0438\u0441\u043b\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b 0-9, A-F.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0432\u0441\u0435 \u0445\u043e\u0434\u044b, \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 XBYC, \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>X \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb (\u043f\u043e\u043b\u043d\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u0446\u0438\u0444\u0440\u044b \u0438 \u0435\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435);<\/p>\n<\/li>\n<li>\n<p>Y \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb (\u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0446\u0438\u0444\u0440\u044b, \u043d\u043e \u043d\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 error.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvGame \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0445\u043e\u0434\u043e\u0432 \u0438\u0433\u0440\u043e\u043a\u0430. \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0445\u043e\u0434\u0430\u043c\u0438 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0445\u043e\u0434\u043e\u0432. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u0438\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u043a\u043e\u0434\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b, \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0445\u043e\u0434 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0440\u043e\u0432\u043d\u043e \u0438\u0437 4 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0446\u0438\u0444\u0440. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a isError \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c.<\/p>\n<pre><code class=\"pgsql\">select N,        code,        not (code !~ '(.).*\\1' and code ~ '^[0-9A-F]{4}$') isError  from unnest(('{'||upper(current_setting('bulls.game'))||'}')::text[])       with ordinality as G(code,N)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> n | code | iserror  ---+------+---------  1 | 56F8 | f  2 | 9D13 | f  3 | 3426 | f  4 | 25B3 | f  5 | 6D9A | f  6 | 3029 | f (6 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvSecretCode \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.\u0421\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a isError \u0432 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.\u00a0<\/p>\n<pre><code class=\"pgsql\">select code,        not (code !~ '(.).*\\1' and code ~ '^[0-9A-F]{4}$') as isError from upper(current_setting('bulls.secretcode')) as code<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">code | iserror  ------+---------  3D29 | f (1 row)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvCodes \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb. \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb, \u0435\u0441\u043b\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb, \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0439. \u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u043d\u0435\u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0439.<\/p>\n<pre><code class=\"pgsql\">select N,        code,        (SELECT COUNT(*) FROM unnest(string_to_array(g.code, NULL)) WITH ORDINALITY AS gv(digit, pos)          JOIN unnest(string_to_array((select code from lvSecretCode), NULL)) WITH ORDINALITY AS sc(digit, pos)         ON gv.pos = sc.pos AND gv.digit = sc.digit) as bulls,        (SELECT COUNT(*) FROM unnest(string_to_array(g.code, NULL)) WITH ORDINALITY AS gv(digit, pos)            JOIN unnest(string_to_array((select code from lvSecretCode), NULL)) WITH ORDINALITY AS sc(digit, pos)             ON gv.pos != sc.pos AND gv.digit = sc.digit) as cows   from lvgame g  where not exists (select 1 from lvgame where isError)    and not exists (select 1 from lvSecretCode where isError)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> n | code | bulls | cows  ---+------+-------+------  1 | 56F8 |     0 |    0  2 | 9D13 |     1 |    2  3 | 3426 |     2 |    0  4 | 25B3 |     0 |    2  5 | 6D9A |     1 |    1  6 | 3029 |     3 |    0 (6 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443. \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043a\u043e\u0434\u043e\u0432 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb. \u0415\u0441\u043b\u0438 \u0431\u044b\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u2018error\u2019.\u00a0<\/p>\n<pre><code class=\"pgsql\">select coalesce (string_agg(code||' '||bulls||'B'||cows||'C',',' order by n),'error') as gameparty   from lvCodes;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">                          gameparty                           -------------------------------------------------------------  56F8 0B0C,9D13 1B2C,3426 2B0C,25B3 0B2C,6D9A 1B1C,3029 3B0C (1 row)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">with lvgame as (    select N,           code,           not (code !~ '(.).*\\1' and code ~ '^[0-9A-F]{4}$') as isError      from unnest(('{'||upper(current_setting('bulls.game'))||'}')::text[]) with ordinality as G(code,N) ), lvSecretCode as (    select code,           not (code !~ '(.).*\\1' and code ~ '^[0-9A-F]{4}$') as isError       from upper(current_setting('bulls.secretcode')) as code ), lvCodes as( select N,        code,        (select COUNT(*)            from unnest(string_to_array(g.code, NULL)) with ordinality as gv(digit, pos)            JOIN unnest(string_to_array((select code from lvSecretCode), NULL)) with ordinality as sc(digit, pos)             ON gv.pos = sc.pos AND gv.digit = sc.digit) as bulls,        (select COUNT(*) from unnest(string_to_array(g.code, NULL)) with ordinality as gv(digit, pos)            JOIN unnest(string_to_array((select code from lvSecretCode), NULL)) with ordinality as sc(digit, pos)             ON gv.pos != sc.pos AND gv.digit = sc.digit) as cows   from lvgame g  where not exists (select 1 from lvgame where isError)    and not exists (select 1 from lvSecretCode where isError) ) select coalesce (string_agg(code||' '||bulls||'B'||cows||'C',',' order by n),'error') as gameparty   from lvCodes;<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 5. \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0445\u043e\u0434\u0430 \u0438\u0433\u0440\u044b \u00ab\u0411\u044b\u043a\u0438 \u0438 \u043a\u043e\u0440\u043e\u0432\u044b\u00bb<\/h3>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b \u0431\u044b\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b <a href=\"#%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u043d\u0435\u0435<\/a>.<\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0412\u0430\u043c \u0434\u0430\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u044b\u043a\u043e\u0432 \u0438 \u043a\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0445\u043e\u0434\u0430. \u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 4 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0445\u043e\u0434\u0430 \u043a\u0430\u043a \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0445\u043e\u0434\u043e\u0432. \u0415\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b, \u043b\u0438\u0431\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u044b\u043a\u043e\u0432 \u0438\u043b\u0438 \u043a\u043e\u0440\u043e\u0432, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0445\u043e\u0434 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d. \u0412\u0441\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 bulls.gameparty.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"pgsql\">set bulls.gameparty='56f8 0B0C,9D13 1B2C,341F 1B0C,25B3 0B2C';<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/p>\n<pre><code class=\"pgsql\"> code  ------  3D9B (1 row)<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0445\u043e\u0434\u043e\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0440\u0438 \u0447\u0438\u0441\u043b\u0430 3D9B, 3D92 \u0438 3D29, \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0438\u0437 \u043d\u0438\u0445 \u2014 3D9B.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439: \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0447\u0438\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u0439 \u0446\u0438\u0444\u0440\u043e\u0439.<\/p>\n<pre><code class=\"pgsql\">set bulls.gameparty='56F8 0B0C,9D13 1B2C,341H 1B0C,25B3 0B2C';<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/p>\n<pre><code class=\"pgsql\"> code  ------ (0 rows)<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043f\u0435\u0440\u0435\u043a\u043b\u0438\u043a\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439. \u041f\u043e \u0441\u0443\u0442\u0438, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u0430 \u044d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430, \u043d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u0445 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u0441\u0434\u0435\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441 4-\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0422\u0430\u043a \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u043a\u0430. \u0411\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043c\u044b \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0438 \u0434\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0435\u0433\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0445\u043e\u0434\u043e\u0432 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 9999 XBYC, \u0433\u0434\u0435 9999 \u2014 \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, X \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb, Y \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0445\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b 0-9, A-F.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u0441\u043b\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u2014 \u0446\u0438\u0444\u0440\u044b \u043e\u0442 0 \u0434\u043e 4.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0442\u044b\u0440\u0435\u0445\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0445\u043e\u0434\u0430\u043c\u0438 \u0438 \u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvGameParty \u2014 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0445\u043e\u0434\u043e\u0432. \u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"pgsql\">select N,        substring(code,'^[0-9A-F]{4} ') code,        substring(code,' (\\d)B.C')::int bulls,        substring(code,' .B(\\d)C')::int cows   from unnest(('{'||upper(current_setting('bulls.gameparty'))||'}')::text[]) with ordinality as G(code,N) <\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> n | code  | bulls | cows  ---+-------+-------+------  1 | 56F8  |     0 |    0  2 | 9D13  |     1 |    2  3 | 341F  |     1 |    0  4 | 25B3  |     0 |    2 (4 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvPossibleCodes \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0445\u043e\u0434\u043e\u0432. \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0445\u043e\u0434\u043e\u0432 \u043e\u0442 0000 \u0434\u043e FFFF, \u0438\u0437 \u043d\u0438\u0445 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u043a \u0445\u043e\u0434\u0430\u043c (\u0432\u0441\u0435 \u0446\u0438\u0444\u0440\u044b \u0432 \u0447\u0438\u0441\u043b\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b). \u0427\u0438\u0441\u043b\u0430 \u0431\u0443\u0434\u0443\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b.<\/p>\n<pre><code class=\"pgsql\">select code::CHAR(4)   from (select LPAD(upper(to_hex(num)), 4, '0') AS code           from generate_series(0, 65535) AS num)  where code !~ '(.).*\\1'    and code ~ '^[0-9A-F]{4}$'     and not exists (select 1                       from lvGameParty GP                      where (GP.code is null or GP.bulls is null                         or  GP.cows is null or GP.code ~ '(.).*\\1'))<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> code  ------  0123  0124  0125  0126  0127  0128  0129  012A  012B  012C  012D  012E  012F  0132  0134  0135  0136  0137  0138  0139 ...<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 lvValidCodes \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0445\u043e\u0434\u0430 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0433\u0440\u044b. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0445\u043e\u0434\u0430\u043c \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0433\u0440\u044b. \u041e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0447\u0438\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u0441\u0435\u043c \u0445\u043e\u0434\u0430\u043c \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0443 \u043d\u0438\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0431\u044b\u043a\u043e\u0432\u00bb \u0438 \u00ab\u043a\u043e\u0440\u043e\u0432\u00bb \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0445\u043e\u0434\u043e\u043c \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438.<\/p>\n<pre><code class=\"pgsql\">select pc.code   from lvPossibleCodes pc where not exists        (select 1          from lvGameParty g         where           ((select COUNT(*) from unnest(string_to_array(g.Code, NULL)) with ordinality as gv(digit, pos)              join unnest(string_to_array(pc.Code, NULL)) with ordinality as sc(digit, pos)                on gv.pos = sc.pos AND gv.digit = sc.digit) != g.bulls         or           (select COUNT(*) from unnest(string_to_array(g.Code, NULL)) with ordinality AS gv(digit, pos)              join unnest(string_to_array(pc.Code, NULL)) with ordinality AS sc(digit,pos)                on gv.digit = sc.digit and gv.pos != sc.pos) != g.cows)       )<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> code  ------  3D29  3D92  3D9B (3 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u041e\u043d \u0438\u0437 \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0445\u043e\u0434\u043e\u0432 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438.<\/p>\n<pre><code class=\"pgsql\">select Code  from lvValidCodes order by Code desc limit 1; <\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> code  ------  3D9B (1 row)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">with lvGameParty as (    select N,           substring(code,'^[0-9A-F]{4} ') code, -- \u0431\u0435\u0440\u0435\u043c \u0441\u0430\u043c\u043e \u0447\u0438\u0441\u043b\u043e 4 \u0446\u0438\u0444\u0440\u044b \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0431\u0435\u043b            substring(code,' (\\d)B.C')::int bulls, -- \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u044b\u043a\u043e\u0432           substring(code,' .B(\\d)C')::int cows -- \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u043e\u0432      from unnest(('{'||upper(current_setting('bulls.gameparty'))||'}')::text[]) with ordinality as G(code,N)       ), lvPossibleCodes AS (   select      code::CHAR(4)   from      (select      LPAD(upper(to_hex(num)), 4, '0') AS code   from      generate_series(0, 65535) AS num )       where      code !~ '(.).*\\1' -- \u0432\u0441\u0435 \u0446\u0438\u0444\u0440\u044b \u0432 \u0447\u0438\u0441\u043b\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b     and code ~ '^[0-9A-F]{4}$' -- \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0447\u0442\u043e 4 \u0446\u0438\u0444\u0440\u044b \u0432 16-\u0442\u0438\u0440\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f     -- \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0430\u0440\u0442\u0438\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0445\u043e\u0434\u044b      and not exists (select 1 from lvGameParty GP where (GP.code is null or GP.bulls is null or GP.cows is null or GP.code ~ '(.).*\\1')) ), lvValidCodes AS (   select      pc.code   from      lvPossibleCodes pc   where      not exists (       select 1       from lvGameParty g       where           (           -- \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0431\u044b\u043a\u043e\u0432 \u0438 \u043a\u043e\u0440\u043e\u0432           (select COUNT(*) from unnest(string_to_array(g.Code, NULL)) with ordinality as gv(digit, pos)            join unnest(string_to_array(pc.Code, NULL)) with ordinality as sc(digit, pos)            ON gv.pos = sc.pos AND gv.digit = sc.digit) != g.bulls           OR           (select COUNT(*) from unnest(string_to_array(g.Code, NULL)) with ordinality AS gv(digit, pos)            join unnest(string_to_array(pc.Code, NULL)) with ordinality AS sc(digit,pos)            on gv.digit = sc.digit and gv.pos != sc.pos) != g.cows         )     ) ) select Code    from lvValidCodes  order by Code desc  limit 1;<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>\u041e\u0431\u0449\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f<\/h3>\n<ol>\n<li>\n<p>\u041e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0438. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0438\u0437 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0438. \u0417\u0430\u0447\u0435\u043c \u043f\u0440\u0438\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0435\u0434\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u043d \u0437\u0430\u0432\u0435\u0434\u043e\u043c\u043e \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439?<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435. \u041c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c, \u0441 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432 PostgreSQL \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439. \u0412\u0441\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0418\u0418 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b \u0437\u0430\u043f\u0440\u043e\u0441, \u0438 \u0435\u0433\u043e, \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u0432\u0448\u0438\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443. \u041a\u0430\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435? \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 0 \u0431\u0430\u043b\u043b\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0430\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b, \u043f\u0440\u0438\u0447\u0435\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0437\u044e\u043c\u0435: \u043d\u0430 \u0418\u0418 \u043d\u0430\u0434\u0435\u0439\u0441\u044f, \u043d\u043e \u0441\u0430\u043c \u043d\u0435 \u043f\u043b\u043e\u0448\u0430\u0439. <\/p>\n<\/li>\n<\/ol>\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\/919426\/\"> https:\/\/habr.com\/ru\/articles\/919426\/<\/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>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0432\u043e\u0435 \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043c\u0435\u0436\u0434\u0443\u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0439 \u043e\u043b\u0438\u043c\u043f\u0438\u0430\u0434\u0435 \u00abIT-\u041f\u043b\u0430\u043d\u0435\u0442\u0430\u00bb.\u00a0 \u041a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u0433\u043e\u0434\u044b, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0441\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0441 \u043f\u043e SQL, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0442\u0440\u0435\u0445 \u044d\u0442\u0430\u043f\u043e\u0432: \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0443\u0440\u044b, \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043e\u043d\u043b\u0430\u0439\u043d, \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0447\u043d\u044b\u0439 \u0442\u0443\u0440.<\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0442\u0443\u0440\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0441\u0432\u044b\u0448\u0435 4 500 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 245 \u0431\u044b\u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u043d\u044b \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439. \u0412 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447 \u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0442\u0443\u0440\u043e\u0432. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430.<\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 1. \u0421\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0439 \u041a\u0430\u0440\u043b\u0441\u043e\u043d<\/h2>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0435\u043d\u044c\u0435. \u041e\u043d \u043e\u0449\u0443\u0449\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u0434\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u044f\u0434 \u0441\u044a\u0435\u0434\u0430\u0435\u0442 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u043d\u043a\u0438 \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u0432 \u0434\u0435\u043d\u044c, \u0438 \u043f\u0440\u0438\u0442\u043e\u043c, \u0441\u044a\u0435\u0434\u0430\u0435\u0442 \u0437\u0430 \u044d\u0442\u0438 \u0434\u043d\u0438 \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f.<\/p>\n<p>\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u0449\u0443\u0449\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434. \u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043d\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u0435\u043d.<\/p>\n<p>\u0412\u0435\u0441\u044c \u0433\u043e\u0434 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 jam, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u0441\u044a\u0435\u0434\u0430\u043b. \u0418\u043d\u043e\u0433\u0434\u0430 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043e\u0448\u0438\u0431\u0430\u043b\u0441\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0441\u044a\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u043d\u043a\u0438 \u0432\u0430\u0440\u0435\u043d\u044c\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438.<\/p>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<pre><code class=\"pgsql\">CREATE TABLE jam (    at date not null,     qty integer not null check (qty&gt;=0) );<\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0441\u0435\u0431\u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0414\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO jam VALUES  ('2025-01-04',1),('2025-01-05',1),('2025-01-07',1), ('2025-01-08',2),('2025-01-09',2),('2025-01-10',1), ('2025-01-11',1),('2025-01-12',2),('2025-01-13',1), ('2025-01-14',1),('2025-01-15',1);<\/code><\/pre>\n<p>\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"pgsql\"> happydays  -----------          2 (1 row) <\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u0435\u043b \u0432\u0430\u0440\u0435\u043d\u044c\u0435 3 \u0434\u043d\u044f \u043f\u043e\u0434\u0440\u044f\u0434 \u0431\u0435\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432, \u0438 \u0432 \u044d\u0442\u0438 \u0434\u043d\u0438 \u043e\u043d \u0441\u044a\u0435\u0434\u0430\u043b \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 4 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043d\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u0442\u0441\u044f \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u043d\u0438 \u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u0435\u043d.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u044f\u0432\u043d\u043e \u043d\u0435 \u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0442\u0430\u043a \u0438 \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u043c.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435:<\/p>\n<ol>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430 \u043e\u0434\u043d\u0443 \u0434\u0430\u0442\u0443 (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0441 qty &gt; 0)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c qty = 0 (\u041a\u0430\u0440\u043b\u0441\u043e\u043d \u043d\u0435 \u0435\u043b \u0432\u0430\u0440\u0435\u043d\u044c\u0435 \u0432 \u044d\u0442\u043e\u0442 \u0434\u0435\u043d\u044c, \u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b).<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432. \u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 RANGE \u0432\u043c\u0435\u0441\u0442\u043e ROWS \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438 \u0432 \u0434\u0430\u0442\u0430\u0445.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0434\u0430\u0442\u044b, \u0433\u0434\u0435 \u0431\u044b\u043b\u043e \u0441\u044a\u0435\u0434\u0435\u043d\u043e 0 \u0431\u0430\u043d\u043e\u043a \u0432\u0430\u0440\u0435\u043d\u044c\u044f, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0434\u0430\u0442\u043e\u0439.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO jam VALUES('2025-01-04',1),('2025-01-05',1),('2025-01-07',1),                       ('2025-01-08',1),('2025-01-09',1),('2025-01-10',1),                       ('2025-01-08',1),('2025-01-09',0),('2025-01-10',1),                       ('2025-01-11',1),('2025-01-12',1),('2025-01-13',1),                       ('2025-01-11',0),('2025-01-12',1),('2025-01-13',0),                       ('2025-01-16',2),('2025-01-16',0),('2025-01-17',0),                       ('2025-01-17',1),('2025-01-18',1),('2025-01-19',2),                       ('2025-01-20',1),('2025-01-21',1),('2025-01-22',2),                       ('2025-01-23',1),('2025-01-25',6),('2025-01-26',1);<\/code><\/pre>\n<pre><code class=\"pgsql\">olymp=# select * from jam order by at;      at     | qty  ------------+-----  2025-01-04 |   1  2025-01-05 |   1  2025-01-07 |   1  2025-01-08 |   1  2025-01-08 |   1  2025-01-09 |   1  2025-01-09 |   0  2025-01-10 |   1  2025-01-10 |   1  2025-01-11 |   1  2025-01-11 |   0  2025-01-12 |   1  2025-01-12 |   1  2025-01-13 |   1  2025-01-13 |   0  2025-01-16 |   2  2025-01-16 |   0  2025-01-17 |   0  2025-01-17 |   1  2025-01-18 |   1  2025-01-19 |   2  2025-01-20 |   1  2025-01-21 |   1  2025-01-22 |   2  2025-01-23 |   1  2025-01-25 |   6  2025-01-26 |   1 (27 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_jam &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>\u0418\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0434\u043d\u0438 \u0441 qty=0 \u0438 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0434\u0430\u0442\u0430\u043c.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        SUM(qty) AS qty   FROM jam  GROUP BY at HAVING SUM(qty) &gt; 0<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | qty  ------------+-----  2025-01-04 |   1  2025-01-05 |   1  2025-01-07 |   1  2025-01-08 |   2  2025-01-09 |   1  2025-01-10 |   2  2025-01-11 |   1  2025-01-12 |   2  2025-01-13 |   1  2025-01-16 |   2  2025-01-17 |   1  2025-01-18 |   1  2025-01-19 |   2  2025-01-20 |   1  2025-01-21 |   1  2025-01-22 |   2  2025-01-23 |   1  2025-01-25 |   6  2025-01-26 |   1 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_courage \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u043d\u0438 \u0441 \u043f\u0440\u0438\u043b\u0438\u0432\u0430\u043c\u0438 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u00ab3 \u0434\u043d\u044f \u043f\u043e\u0434\u0440\u044f\u0434 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0431\u0430\u043d\u043e\u043a \u0437\u0430 \u044d\u0442\u043e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u00bb. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u043e\u043a\u043d\u043e\u043c, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u0435\u043d\u044c \u0438 \u0434\u0432\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c range \u043f\u043e \u0434\u0430\u0442\u0430\u043c, \u0430 \u043d\u0435 \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c). \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u00a0 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 count(*)=3, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        CASE WHEN COUNT(*) over w = 3 AND SUM(qty) over w &gt; 3              THEN 1              ELSE 0          END AS is_courage   FROM daily_jam WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '2' DAY PRECEDING                 AND CURRENT ROW)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | is_courage  ------------+------------  2025-01-04 |          0  2025-01-05 |          0  2025-01-07 |          0  2025-01-08 |          0  2025-01-09 |          1  2025-01-10 |          1  2025-01-11 |          1  2025-01-12 |          1  2025-01-13 |          1  2025-01-16 |          0  2025-01-17 |          0  2025-01-18 |          1  2025-01-19 |          1  2025-01-20 |          1  2025-01-21 |          1  2025-01-22 |          1  2025-01-23 |          1  2025-01-25 |          0  2025-01-26 |          0 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441 daily_happy &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0435 \u0434\u043d\u0438. \u0414\u0435\u043d\u044c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0439, \u0435\u0441\u043b\u0438 \u0443 \u041a\u0430\u0440\u043b\u0441\u043e\u043d\u0430 5 \u0434\u043d\u0435\u0439 \u043f\u043e\u0434\u0440\u044f\u0434 \u0431\u044b\u043b \u043f\u0440\u0438\u043b\u0438\u0432 \u0431\u043e\u0434\u0440\u043e\u0441\u0442\u0438. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u0434\u043d\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<pre><code class=\"pgsql\">SELECT at AS at,        is_courage,        CASE WHEN SUM(is_courage) OVER w = 5              THEN 1              ELSE 0          END AS is_happy   FROM daily_courage WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '4' DAY PRECEDING                 AND CURRENT ROW)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">     at     | is_courage | is_happy  ------------+------------+----------  2025-01-04 |          0 |        0  2025-01-05 |          0 |        0  2025-01-07 |          0 |        0  2025-01-08 |          0 |        0  2025-01-09 |          1 |        0  2025-01-10 |          1 |        0  2025-01-11 |          1 |        0  2025-01-12 |          1 |        0  2025-01-13 |          1 |        1  2025-01-16 |          0 |        0  2025-01-17 |          0 |        0  2025-01-18 |          1 |        0  2025-01-19 |          1 |        0  2025-01-20 |          1 |        0  2025-01-21 |          1 |        0  2025-01-22 |          1 |        1  2025-01-23 |          1 |        1  2025-01-25 |          0 |        0  2025-01-26 |          0 |        0 (19 rows)<\/code><\/pre>\n<\/div>\n<\/details>\n<\/li>\n<li>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u0445 \u0434\u043d\u0435\u0439.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\">WITH daily_jam AS ( SELECT at AS at,        SUM(qty) AS qty   FROM jam  GROUP BY at HAVING SUM(qty) &gt; 0 ), daily_courage AS ( SELECT at AS at,        CASE WHEN COUNT(*) over w = 3 AND SUM(qty) over w &gt; 3              THEN 1              ELSE 0          END AS is_courage   FROM daily_jam WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '2' DAY PRECEDING                 AND CURRENT ROW) ), daily_happy AS ( SELECT at AS at,        CASE WHEN SUM(is_courage) OVER w = 5              THEN 1              ELSE 0          END AS is_happy   FROM daily_courage WINDOW w AS (ORDER BY at RANGE BETWEEN INTERVAL '4' DAY PRECEDING                AND CURRENT ROW) ) SELECT COALESCE(SUM(is_happy), 0) AS happydays   FROM daily_happy;<\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0420\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<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"pgsql\"> happydays  -----------          3 (1 row)<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438:<\/p>\n<ol>\n<li>\n<p>\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u043e \u0441\u0434\u0432\u0438\u0433\u0430\u043c\u0438 \u043d\u0430 1\u20132 \u0434\u043d\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 LEAD (LAG) \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c (\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c) \u0441\u0442\u0440\u043e\u043a\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044f \u0441 \u0448\u0430\u0433\u043e\u043c 1 \u0434\u0435\u043d\u044c \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445:<\/p>\n<ol>\n<li>\n<p>\u041d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043d\u0438 \u0441 qty = 0.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u044f\u043b\u0430\u0441\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043c\u0438 \u0432 \u0434\u0430\u0442\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u0434\u0435\u043d\u044c.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0430 2. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/h2>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL. \u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params:<\/p>\n<pre><code class=\"pgsql\">CREATE TABLE params (        parameter_name TEXT NOT NULL,        ts timestamp NOT NULL,        value  TEXT NULL,        PRIMARY KEY (parameter_name,ts));<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00e1\u044f \u043c\u0435\u0442\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 params \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c null \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00f3\u0439 \u043c\u0435\u0442\u043a\u043e\u0439.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u0442\u0430\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u0432\u0441\u0435.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0414\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"pgsql\">INSERT INTO params (parameter_name, ts, value) VALUES ('max_connections', '2025-01-10 11:30', '500'),        ('max_connections', '2025-01-14 09:30', NULL),        ('work_mem', '2025-01-11 08:35', '8MB'),        ('work_mem', '2025-01-17 14:00', NULL),        ('shared_buffers', '2025-01-14 10:00', '20000'),        ('shared_buffers', '2025-01-15 07:40', NULL),        ('temp_buffers', '2025-01-22 11:15', '2000'),        ('maintenance_work_mem', '2025-01-19 10:20', '1000'),        ('maintenance_work_mem', '2025-01-19 13:26', null),        ('max_worker_processes', '2025-01-09 00:30', '16'),        ('max_worker_processes', '2025-01-14 08:30', null);<\/code><\/pre>\n<p>\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"pgsql\">      ts_start       |       ts_end        | parameters  ---------------------+---------------------+------------  2025-01-11 08:35:00 | 2025-01-14 08:30:00 |          3 (1 row)<\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430:<\/p>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b, \u0433\u0434\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441<\/p>\n<\/li>\n<\/ol>\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-464468","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464468","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=464468"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464468\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}