{"id":371275,"date":"2024-05-21T04:44:50","date_gmt":"2024-05-21T04:44:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=371275"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T04:44:50","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=371275","title":{"rendered":"<span>\u0417\u0430\u0434\u0430\u0447\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432<\/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>\u0423\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 SQL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u0433\u0440\u0443\u043f\u043f \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b. \u0412 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u2014 \u044d\u0442\u043e \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0412 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0441\u0435\u0430\u043d\u0441\u044b, \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u0433\u043e\u0441\u043f\u0438\u0442\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043c\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u043e\u0432 \u043d\u0430 \u0434\u043e\u0440\u043e\u0433\u0435, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440 \u0438 \u0442.\u0434.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c <a href=\"https:\/\/www.itprotoday.com\/sql-server\/new-solution-packing-intervals-problem\">\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0441\u0435\u0430\u043d\u0441\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u043e\u0432<\/a>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u0435 \u0442\u0435\u0440\u043c\u0438\u043d <a href=\"https:\/\/www.google.com\/search?q=packing+intervals+SQL\"><em>packing intervals SQL<\/em><\/a>, \u0442\u043e \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0438 \u043c\u043e\u044e.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u044f \u0438\u043c\u0435\u043b \u0434\u0435\u043b\u043e \u0441\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u0443 \u0432\u0441\u0435\u0445 \u043d\u0438\u0445 \u0431\u044b\u043b\u043e \u043d\u0435\u0447\u0442\u043e \u043e\u0431\u0449\u0435\u0435, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043b\u043e \u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u0438\u0437 \u0441\u0435\u0431\u044f \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b. \u041e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u0440\u0435\u0437\u043a\u0438 \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u0439, \u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0433\u0440\u0443\u043f\u043f \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432.<\/p>\n<p>\u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u044f\u0445 \u043f\u043e T-SQL, \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438, <a href=\"https:\/\/stackoverflow.com\/users\/3416551\/pwilcox\">\u041f\u043e\u043b \u0423\u0438\u043b\u043a\u043e\u043a\u0441<\/a> (Paul Wilcox) \u0438\u0437 \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0414\u0436\u043e\u043d\u0430 \u0425\u043e\u043f\u043a\u0438\u043d\u0441\u0430 \u043f\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0441\u044f, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043c\u0435\u043d\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438. \u041e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043c\u043d\u0435 <a href=\"https:\/\/stackoverflow.com\/questions\/59417570\/packing-ranges-in-two-dimensions\">\u043f\u043e\u0441\u0442 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u043e\u0434\u0430\u043c\u0438 \u0440\u0430\u043d\u0435\u0435, \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u043a\u043e\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0433\u0435. \u042f \u043f\u043e\u043c\u043d\u044e, \u043a\u0430\u043a \u041f\u043e\u043b \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0436\u0435\u0441\u0442\u044b \u0440\u0443\u043a, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0435 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u043d\u043e\u0433\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u044e. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043d\u0435 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043c\u043d\u0435 \u043d\u0435\u0447\u0435\u0433\u043e \u0431\u044b\u043b\u043e \u0435\u043c\u0443 \u0442\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u044f \u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043d\u0435\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0443\u0442\u0440\u043e\u043c.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u044f \u043d\u0430\u0437\u044b\u0432\u0430\u044e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c\u0438. \u0427\u0442\u043e \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0442\u0430\u043a \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u044b\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0439 \u0438 \u0438\u043d\u0442\u0440\u0438\u0433\u0443\u044e\u0449\u0435\u0439. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u044f \u043c\u043e\u0433 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u041f\u043e\u043b \u0431\u044b\u043b \u043e\u0447\u0435\u043d\u044c \u043e\u043f\u044b\u0442\u043d\u044b\u043c \u0438 \u0443\u043c\u043d\u044b\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0441\u043f\u0443\u0441\u0442\u044f \u0433\u043e\u0434\u044b, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440, \u043a\u0430\u043a \u043e\u043d \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0438\u0441\u043a\u0430\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0437\u043d\u0430\u0447\u0438\u0442, \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u043e \u0437\u0430\u0434\u0430\u0447\u0435 \u0434\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u041f\u043e\u043b\u0430 \u0438 \u043e \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u041f\u043e\u043b \u0441\u0430\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043b \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438.<\/p>\n<p>\u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0438 \u0441 \u041f\u043e\u043b\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u0434\u043b\u044f \u0432\u0430\u0441.\u00a0 \u042f \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/stackoverflow.com\/questions\/59417570\/packing-ranges-in-two-dimensions\">\u043f\u043e\u0441\u0442 \u041f\u043e\u043b\u0430<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0443\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0434\u0430\u0447\u0435 \u0438 \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a\u043e\u0434 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/12\/ItzikBenGanTwo-Dimensional-Interval-Packing-Challenge.zip\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\u00a0<\/h3>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f\u043c\u0438 \u0437\u0430\u043d\u044f\u0442\u0438\u0439 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Schedule, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"sql\">SET NOCOUNT ON; USE tempdb; DROP TABLE IF EXISTS dbo.Schedule; CREATE TABLE dbo.Schedule (   id         INT     NOT NULL       CONSTRAINT PK_Schedule PRIMARY KEY,   student    CHAR(3) NOT NULL,   fromdate   INT     NOT NULL,   todate     INT     NOT NULL,   fromperiod INT     NOT NULL,   toperiod   INT     NOT NULL ); INSERT INTO dbo.Schedule(id, student, fromdate, todate,  fromperiod, toperiod) VALUES     (1, 'Amy',  1,  7,  7,  9),     (2, 'Amy',  3,  9,  5,  8),      (3, 'Amy', 10, 12,  1,  3),      (4, 'Ted',  1,  5, 11, 14),     (5, 'Ted',  7, 11, 13, 16);<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0441\u0442\u0443\u0434\u0435\u043d\u0442, \u0434\u0430\u0442\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 (<code>fromdate<\/code>) \u0438 \u0434\u0430\u0442\u0430 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f (<code>todate<\/code>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 (<code>fromperiod<\/code>) \u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0430 (<code>toperiod<\/code>). \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0445 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a:<\/p>\n<pre><code class=\"sql\">SELECT student,   GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION('   + STRING_AGG(CONCAT('POLYGON((',fromdate,' ',fromperiod, ',',                                  fromdate,' ',toperiod + 1, ',',                                  todate + 1,' ',toperiod + 1,',',                                  todate + 1,' ',fromperiod,',',                                  fromdate,' ',fromperiod ,                       '))'), ',')   + ')', 0) AS shape FROM dbo.Schedule GROUP BY student;<\/code><\/pre>\n<p>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 1 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Spatial results SSMS.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/522\/321\/3fc\/5223213fce777f7f4efccf2296b95ef1.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1: \u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435.\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1: \u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435.\" width=\"609\" height=\"662\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/522\/321\/3fc\/5223213fce777f7f4efccf2296b95ef1.png\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1: \u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435.<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0441\u044c X \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0434\u0430\u0442, \u0430 \u043e\u0441\u044c Y \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0443 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f\u043c\u0438 1 \u0438 2 \u042d\u043c\u0438 (Amy). \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0449\u0435\u0442 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u042d\u043c\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0434\u0430\u0442\u0443 4 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434 8:<\/p>\n<pre><code class=\"sql\">SELECT id, student, fromdate, todate, fromperiod, toperiod FROM dbo.Schedule WHERE student = 'Amy'   AND 4 BETWEEN fromdate AND todate   AND 8 BETWEEN fromperiod AND toperiod;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439:<\/p>\n<pre><code>id          student fromdate    todate      fromperiod  toperiod ----------- ------- ----------- ----------- ----------- -------- 1           Amy     1           7           7           9 2           Amy     3           9           5           8<\/code><\/pre>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 (\u0434\u0430\u0442\u0430, \u043f\u0435\u0440\u0438\u043e\u0434) \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f. \u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f\u043c\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0434\u0430\u0442 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0432\u0432\u043e\u0434\u0438\u043c\u0443\u044e \u0442\u043e\u0447\u043a\u0443 (\u0434\u0430\u0442\u0430, \u043f\u0435\u0440\u0438\u043e\u0434).<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0434\u0430\u0442 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 2 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f85\/868\/922\/f85868922538691fb005ea0174218721.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2: \u0418\u0441\u043a\u043e\u043c\u044b\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u043a\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2: \u0418\u0441\u043a\u043e\u043c\u044b\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u043a\" width=\"514\" height=\"640\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f85\/868\/922\/f85868922538691fb005ea0174218721.png\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2: \u0418\u0441\u043a\u043e\u043c\u044b\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0435\u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0442\u043e \u0432\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0435 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0437\u044b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0443\u044e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0437\u044b. \u0418\u043b\u0438 \u0434\u0430\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0435\u0437\u043e\u0432. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u043c\u0438, \u0442\u043e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>student fromdate    todate      fromperiod  toperiod ------- ----------- ----------- ----------- ----------- Amy     1           2           7           9 Amy     3           7           5           9 Amy     8           9           5           8 Amy     10          12          1           3 Ted     1           5           11          14 Ted     7           11          13          16<\/code><\/pre>\n<p>\u042f \u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430 \u0440\u0430\u0431\u043e\u0442\u0443!<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438<\/h3>\n<p>\u041c\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u0442\u0430\u043f\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u043e\u0439 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 (Unpack\/Pack). \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Schedule \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0430\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0435\u0433\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0412\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u044b:<\/p>\n<pre><code class=\"sql\">SELECT id, student, fromperiod, toperiod FROM dbo.Schedule ORDER BY student, fromperiod, toperiod;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>id          student fromperiod  toperiod ----------- ------- ----------- ----------- 3           Amy     1           3 2           Amy     5           8 1           Amy     7           9 4           Ted     11          14 5           Ted     13          16<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0443\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0435\u043d\u0438\u043a\u0430. \u0412\u043e\u0442 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430\u043c\u0438:<\/p>\n<pre><code>student fromperiod  toperiod ------- ----------- ----------- Amy     1           3 Amy     5           9 Ted     11          16<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u043f\u0430\u043a\u0443\u0439\u0442\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435 \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/livebook.manning.com\/book\/sql-server-mvp-deep-dives\/chapter-5\/ch05ex09\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u043e\u0441\u0442\u0440\u043e\u0432\u043e\u0432<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443, \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0448\u0430\u0433\u0430 1. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0434\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u2014 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f integer, \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u042d\u043c\u0438 \u0441 <code>fromperiod 5<\/code> \u0438 <code>toperiod 8<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u043d \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <code>{5, 6, 7, 8}<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Azure SQL \u0438\u043b\u0438 SQL Server 2022 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>GENERATE_SERIES<\/code>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"sql\">SELECT S.id, S.student, P.value AS p FROM dbo.Schedule AS S   CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ORDER BY S.student, p, S.id;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>id          student p ----------- ------- ----------- 3           Amy     1 3           Amy     2 3           Amy     3 2           Amy     5 2           Amy     6 1           Amy     7 2           Amy     7 1           Amy     8 2           Amy     8 1           Amy     9 4           Ted     11 4           Ted     12 4           Ted     13 5           Ted     13 4           Ted     14 5           Ted     14 5           Ted     15 5           Ted     16<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>GENERATE_SERIES<\/code> \u043d\u0435\u0442 \u0432 \u0432\u0430\u0448\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0440\u044f\u0436\u0435\u043d\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438\u0431\u043e <a href=\"https:\/\/sqlperformance.com\/2021\/05\/t-sql-queries\/number-series-solutions-5\">\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e<\/a>, \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<p>\u0428\u0430\u0433 2 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043d\u0435\u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 p, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430\u043c\u0438. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u042d\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 <code>5<\/code> \u0438 <code>9: {5, 6, 7, 7, 8, 8, 9}<\/code>. \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 p, \u043c\u0438\u043d\u0443\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043b\u043e\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0433\u0430 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b) \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 p, \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432. \u0412\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f, \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0433\u0430:<\/p>\n<pre><code class=\"sql\">SELECT S.id, S.student, P.value AS p,   DENSE_RANK() OVER(PARTITION BY S.student ORDER BY P.value)                                                       AS drk,   P.value - DENSE_RANK() OVER(PARTITION BY S.student                                ORDER BY P.value) AS grp_p FROM dbo.Schedule AS S   CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ORDER BY S.student, p, S.id;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>id          student p      drk       grp_p ----------- ------- ------ --------- -------- 3           Amy     1      1         0 3           Amy     2      2         0 3           Amy     3      3         0 2           Amy     5      4         1 2           Amy     6      5         1 1           Amy     7      6         1 2           Amy     7      6         1 1           Amy     8      7         1 2           Amy     8      7         1 1           Amy     9      8         1 4           Ted     11     1         10 4           Ted     12     2         10 4           Ted     13     3         10 5           Ted     13     3         10 4           Ted     14     4         10 5           Ted     14     4         10 5           Ted     15     5         10 5           Ted     16     6         10<\/code><\/pre>\n<p>\u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b (<code>grp_p<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 3 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0433\u0440\u0443\u043f\u043f\u044b \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432 <code>MIN(p)<\/code> \u0438 <code>MAX(p)<\/code> \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"sql\">WITH C AS (   SELECT S.id, S.student, P.value AS p,     DENSE_RANK() OVER(PARTITION BY S.student ORDER BY P.value)                                                         AS drk,     P.value - DENSE_RANK() OVER(PARTITION BY S.student                                  ORDER BY P.value) AS grp_p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ) SELECT student, MIN(p) AS fromperiod, MAX(p) AS toperiod FROM C GROUP BY student, grp_p ORDER BY student, fromperiod;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code>student fromperiod  toperiod ------- ----------- ----------- Amy     1           3 Amy     5           9 Ted     11          16<\/code><\/pre>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u0430 \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b, \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u043b\u0435\u043d\u043e\u0432. \u041d\u043e \u043e\u043d\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438<\/h4>\n<p>\u0412\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u043e\u0439 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438, \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438. \u0425\u0438\u0442\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u2014 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041d\u0430 \u0448\u0430\u0433\u0435 1 \u043c\u044b \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u0442 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0434\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>date (d)<\/code>, <code>period (p)<\/code>. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0448\u0430\u0433 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435, \u043a\u0430\u043a \u043f\u0438\u043a\u0441\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u041f\u043e\u043b\u0443 \u0437\u0430 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044e!) \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0441 \u0440\u0438\u0441\u0443\u043d\u043a\u0430 1, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435. \u0412\u043e\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0433\u0430:<\/p>\n<pre><code class=\"sql\">SELECT S.id, S.student, D.value AS d, P.value AS p FROM dbo.Schedule AS S   CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D   CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ORDER BY S.student, d, p, S.id;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>id          student d           p ----------- ------- ----------- ----------- 1           Amy     1           7 1           Amy     1           8 1           Amy     1           9 1           Amy     2           7 1           Amy     2           8 1           Amy     2           9 2           Amy     3           5 2           Amy     3           6 1           Amy     3           7 2           Amy     3           7 1           Amy     3           8 2           Amy     3           8 1           Amy     3           9 2           Amy     4           5 2           Amy     4           6 1           Amy     4           7 2           Amy     4           7 1           Amy     4           8 2           Amy     4           8 1           Amy     4           9 2           Amy     5           5 2           Amy     5           6 1           Amy     5           7 2           Amy     5           7 1           Amy     5           8 2           Amy     5           8 1           Amy     5           9 2           Amy     6           5 2           Amy     6           6 1           Amy     6           7 2           Amy     6           7 1           Amy     6           8 2           Amy     6           8 1           Amy     6           9 2           Amy     7           5 2           Amy     7           6 1           Amy     7           7 2           Amy     7           7 1           Amy     7           8 2           Amy     7           8 1           Amy     7           9 2           Amy     8           5 2           Amy     8           6 2           Amy     8           7 2           Amy     8           8 2           Amy     9           5 2           Amy     9           6 2           Amy     9           7 2           Amy     9           8 3           Amy     10          1 3           Amy     10          2 3           Amy     10          3 3           Amy     11          1 3           Amy     11          2 3           Amy     11          3 3           Amy     12          1 3           Amy     12          2 3           Amy     12          3 ...<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0448\u0430\u0433\u0430 1 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<pre><code class=\"sql\">WITH Pixels AS (   SELECT S.id, S.student, D.value AS d, P.value AS p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ) SELECT student,   GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION('     + STRING_AGG(CONCAT('POLYGON((', d    , ' ', p    , ',',                                       d    , ' ', p + 1, ',',                                       d + 1, ' ', p + 1, ',',                                       d + 1, ' ', p    , ',',                                       d    , ' ', p    , '))'), ',')      + ')', 0) AS shape FROM Pixels GROUP BY student;<\/code><\/pre>\n<p>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 3 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 Spatial results \u0432 SSMS.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/277\/0f9\/5a1\/2770f95a1482cbf4972884e5b27b97eb.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3: \u041f\u0438\u043a\u0441\u0435\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3: \u041f\u0438\u043a\u0441\u0435\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435\" width=\"510\" height=\"648\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/277\/0f9\/5a1\/2770f95a1482cbf4972884e5b27b97eb.png\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3: \u041f\u0438\u043a\u0441\u0435\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0435\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u044f \u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u0437\u0432\u0430\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0440\u0435\u0437\u043e\u0432, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0448\u0430\u0433\u0443 2. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0440\u0435\u0437\u044b, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u043f\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c \u0438 \u0434\u0430\u0442\u0430\u043c. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 <code>grp_p<\/code> \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 <code>p<\/code> \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0438 \u0433\u0440\u0443\u043f\u043f\u044b <code>d<\/code>. \u0412\u043e\u0442 \u043a\u043e\u0434, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<pre><code class=\"sql\">WITH PixelsAndPeriodGroupIDs AS (   SELECT S.id, S.student, D.value AS d, P.value AS p,     P.value - DENSE_RANK() OVER(PARTITION BY S.student, D.value                                  ORDER BY P.value) AS grp_p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ) SELECT student, d, MIN(p) AS fromperiod, MAX(p) AS toperiod FROM PixelsAndPeriodGroupIDs GROUP BY student, d, grp_p ORDER BY student, d, grp_p;<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0433\u043e CTE (\u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435) <code>PixelsAndPeriodGroupIDs<\/code>, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>grp_p<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e:<\/p>\n<pre><code>id          student d           p           grp_p ----------- ------- ----------- ----------- -------------------- 1           Amy     1           7           6 1           Amy     1           8           6 1           Amy     1           9           6 1           Amy     2           7           6 1           Amy     2           8           6 1           Amy     2           9           6 2           Amy     3           5           4 2           Amy     3           6           4 2           Amy     3           7           4 1           Amy     3           7           4 1           Amy     3           8           4 2           Amy     3           8           4 1           Amy     3           9           4 2           Amy     4           5           4 2           Amy     4           6           4 2           Amy     4           7           4 1           Amy     4           7           4 1           Amy     4           8           4 2           Amy     4           8           4 1           Amy     4           9           4 2           Amy     5           5           4 2           Amy     5           6           4 2           Amy     5           7           4 1           Amy     5           7           4 1           Amy     5           8           4 2           Amy     5           8           4 1           Amy     5           9           4 2           Amy     6           5           4 2           Amy     6           6           4 2           Amy     6           7           4 1           Amy     6           7           4 1           Amy     6           8           4 2           Amy     6           8           4 1           Amy     6           9           4 2           Amy     7           5           4 2           Amy     7           6           4 2           Amy     7           7           4 1           Amy     7           7           4 1           Amy     7           8           4 2           Amy     7           8           4 1           Amy     7           9           4 2           Amy     8           5           4 2           Amy     8           6           4 2           Amy     8           7           4 2           Amy     8           8           4 2           Amy     9           5           4 2           Amy     9           6           4 2           Amy     9           7           4 2           Amy     9           8           4 3           Amy     10          1           0 3           Amy     10          2           0 3           Amy     10          3           0 3           Amy     11          1           0 3           Amy     11          2           0 3           Amy     11          3           0 3           Amy     12          1           0 3           Amy     12          2           0 3           Amy     12          3           0 \u2026<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<pre><code>student d           fromperiod  toperiod ------- ----------- ----------- ----------- Amy     1           7           9 Amy     2           7           9 Amy     3           5           9 Amy     4           5           9 Amy     5           5           9 Amy     6           5           9 Amy     7           5           9 Amy     8           5           8 Amy     9           5           8 Amy     10          1           3 Amy     11          1           3 Amy     12          1           3 Ted     1           11          14 Ted     2           11          14 Ted     3           11          14 Ted     4           11          14 Ted     5           11          14 Ted     7           13          16 Ted     8           13          16 Ted     9           13          16 Ted     10          13          16 Ted     11          13          16<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0430\u0449\u0435\u0433\u043e\u0441\u044f \u0438 \u0434\u0430\u0442\u044b. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"sql\">WITH PixelsAndPeriodGroupIDs AS (   SELECT S.id, S.student, D.value AS d, P.value AS p,     P.value - DENSE_RANK() OVER(PARTITION BY S.student, D.value                                  ORDER BY P.value) AS grp_p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ), DailyPeriodRanges AS (   SELECT student, d, MIN(p) AS fromperiod, MAX(p) AS toperiod   FROM PixelsAndPeriodGroupIDs   GROUP BY student, d, grp_p ) SELECT student,   GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION('     + STRING_AGG(CONCAT('POLYGON((',d,' ',fromperiod  , ',',                                   d,' ',toperiod + 1,',',                                   d + 1,' ',toperiod + 1, ',',                                   d + 1,' ',fromperiod ,',',                                  d,' ',fromperiod,'))'),',')      + ')', 0) AS shape FROM DailyPeriodRanges GROUP BY student;<\/code><\/pre>\n<p>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 4 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0438 Spatial results \u0432 SSMS.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/620\/25a\/fc1\/62025afc115f581c99cc8c94aaca246a.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4: \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u043f\u043e \u0434\u043d\u044f\u043c\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4: \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u043f\u043e \u0434\u043d\u044f\u043c\" width=\"513\" height=\"643\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/620\/25a\/fc1\/62025afc115f581c99cc8c94aaca246a.png\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4: \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u043f\u043e \u0434\u043d\u044f\u043c<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u043e, \u0447\u0435\u0433\u043e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c, \u2014 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u043e\u0434\u043d\u0435\u0432\u043d\u044b\u0439 \u0431\u0438\u043d\u043d\u0438\u0433 (\u0435\u0449\u0435 \u0440\u0430\u0437 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u041f\u043e\u043b\u0443 \u0437\u0430 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044e) \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0417\u0430\u0442\u0435\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 3 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0434\u0430\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0412\u043e\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438:<\/p>\n<pre><code class=\"sql\">WITH PixelsAndPeriodGroupIDs AS (   SELECT S.id, S.student, D.value AS d, P.value AS p,     P.value - DENSE_RANK() OVER(PARTITION BY S.student, D.value                                  ORDER BY P.value) AS grp_p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ), PeriodRangesAndDateGroupIDs AS (   SELECT student, d, MIN(p) AS fromperiod, MAX(p) AS toperiod,     D - DENSE_RANK() OVER(PARTITION BY student, MIN(p), MAX(p)                            ORDER BY d) as grp_d   FROM PixelsAndPeriodGroupIDs   GROUP BY student, d, grp_p ) SELECT student, MIN(d) AS fromdate, MAX(d) AS todate,         fromperiod, toperiod FROM PeriodRangesAndDateGroupIDs GROUP BY student, fromperiod, toperiod, grp_d ORDER BY student, fromdate, fromperiod;<\/code><\/pre>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c CTE (<code>PeriodRangesAndDateGroupIDs<\/code>), \u0433\u0434\u0435 \u0432\u044b \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u043e\u0441\u0442\u0440\u043e\u0432\u043e\u0432, \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0433\u0430 \u0432\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0435 \u0435\u0433\u043e \u043f\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430\u043c \u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 (<code>student<\/code>, <code>MIN(p)<\/code>, <code>MAX(p)<\/code>), \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u0435\u0442\u0435 \u043f\u043e d.<\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u0442\u043e\u0440\u043e\u0433\u043e CTE:<\/p>\n<pre><code>student d           fromperiod  toperiod    grp_d ------- ----------- ----------- ----------- ---------- Amy     10          1           3           9 Amy     11          1           3           9 Amy     12          1           3           9 Amy     8           5           8           7 Amy     9           5           8           7 Amy     3           5           9           2 Amy     4           5           9           2 Amy     5           5           9           2 Amy     6           5           9           2 Amy     7           5           9           2 Amy     1           7           9           0 Amy     2           7           9           0 Ted     1           11          14          0 Ted     2           11          14          0 Ted     3           11          14          0 Ted     4           11          14          0 Ted     5           11          14          0 Ted     7           13          16          6 Ted     8           13          16          6 Ted     9           13          16          6 Ted     10          13          16          6 Ted     11          13          16          6<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c:<\/p>\n<pre><code>student fromdate    todate      fromperiod  toperiod ------- ----------- ----------- ----------- ----------- Amy     1           2           7           9 Amy     3           7           5           9 Amy     8           9           5           8 Amy     10          12          1           3 Ted     1           5           11          14 Ted     7           11          13          16<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">WITH PixelsAndPeriodGroupIDs AS (   SELECT S.id, S.student, D.value AS d, P.value AS p,     P.value - DENSE_RANK() OVER(PARTITION BY S.student, D.value                                 ORDER BY P.value) AS grp_p   FROM dbo.Schedule AS S     CROSS APPLY GENERATE_SERIES(S.fromdate, S.todate) AS D     CROSS APPLY GENERATE_SERIES(S.fromperiod, S.toperiod) AS P ), PeriodRangesAndDateGroupIDs AS (   SELECT student, d, MIN(p) AS fromperiod, MAX(p) AS toperiod,     d - DENSE_RANK() OVER(PARTITION BY student, MIN(p), MAX(p)                            ORDER BY d) as grp_d   FROM PixelsAndPeriodGroupIDs   GROUP BY student, d, grp_p ), NormalizedSchedule AS (   SELECT student, MIN(d) AS fromdate, MAX(d) AS todate,          fromperiod, toperiod   FROM PeriodRangesAndDateGroupIDs   GROUP BY student, fromperiod, toperiod, grp_d ) SELECT student,   GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION('    + STRING_AGG(CONCAT('POLYGON((',fromdate,' ',fromperiod,',',                                   fromdate,' ',toperiod+1,',',                                   todate + 1,' ',toperiod+1,',',                                   todate + 1,' ',fromperiod,',',                                    fromdate  , ' ', fromperiod  ,                                   '))'),       ',')  + ')', 0) AS shape FROM NormalizedSchedule GROUP BY student;<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Spatial results \u0432 SSMS \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0440\u0430\u043d\u0435\u0435 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 2, \u0432 \u0432\u0438\u0434\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u041f\u043e\u043b\u0443 \u0423\u0438\u043b\u043a\u043e\u043a\u0441\u0443 \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u043e \u0434\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0435. \u042d\u0442\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430\u044f \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0430, \u0438 \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435 \u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043d\u0435\u0439. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0438 \u0432\u044b \u0442\u043e\u0436\u0435.<\/p>\n<p>\u0412\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0432\u0430\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u0438\u043a, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u043e\u0441\u0442\u0440\u043e\u0432\u043e\u0432 \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u043d\u0435\u0439 \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438. \u041e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0438 \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b T-SQL.<\/p>\n<p>\u0423\u0434\u0430\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432!<\/p>\n<hr\/>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a \u00abMSSQL vs PostgreSQL \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432 20:00. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b:<\/p>\n<ol>\n<li>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f MS SQL \u0438 PostgreSQL<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0440\u0430\u043d\u043a\u0446\u0438\u0437\u0439 \u0432 MSSQL \u0438 PostgreSQL<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0432 PostgreSQL \u0431\u0435\u0441\u0441\u043c\u044b\u043b\u0435\u043d\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0430\u043c\u0438?<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f T-SQL \u0438 PL\/pgSQL<\/p>\n<\/li>\n<\/ol>\n<p>\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u043a \u043c\u043e\u0436\u043d\u043e<a href=\"https:\/\/otus.pw\/CbGd\/\"> \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/801487\/\"> https:\/\/habr.com\/ru\/articles\/801487\/<\/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>\u0423\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 SQL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u0433\u0440\u0443\u043f\u043f \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b. \u0412 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u2014 \u044d\u0442\u043e \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0412 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0441\u0435\u0430\u043d\u0441\u044b, \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u0433\u043e\u0441\u043f\u0438\u0442\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043c\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u043e\u0432 \u043d\u0430 \u0434\u043e\u0440\u043e\u0433\u0435, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440 \u0438 \u0442.\u0434.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c <a href=\"https:\/\/www.itprotoday.com\/sql-server\/new-solution-packing-intervals-problem\">\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0441\u0435\u0430\u043d\u0441\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u043e\u0432<\/a>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u0435 \u0442\u0435\u0440\u043c\u0438\u043d <a href=\"https:\/\/www.google.com\/search?q=packing+intervals+SQL\"><em>packing intervals SQL<\/em><\/a>, \u0442\u043e \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0438 \u043c\u043e\u044e.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u044f \u0438\u043c\u0435\u043b \u0434\u0435\u043b\u043e \u0441\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u0443 \u0432\u0441\u0435\u0445 \u043d\u0438\u0445 \u0431\u044b\u043b\u043e \u043d\u0435\u0447\u0442\u043e \u043e\u0431\u0449\u0435\u0435, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043b\u043e \u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u0438\u0437 \u0441\u0435\u0431\u044f \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b. \u041e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u0440\u0435\u0437\u043a\u0438 \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u0439, \u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0433\u0440\u0443\u043f\u043f \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432.<\/p>\n<p>\u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u044f\u0445 \u043f\u043e T-SQL, \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438, <a href=\"https:\/\/stackoverflow.com\/users\/3416551\/pwilcox\">\u041f\u043e\u043b \u0423\u0438\u043b\u043a\u043e\u043a\u0441<\/a> (Paul Wilcox) \u0438\u0437 \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 \u0414\u0436\u043e\u043d\u0430 \u0425\u043e\u043f\u043a\u0438\u043d\u0441\u0430 \u043f\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0441\u044f, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043c\u0435\u043d\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438. \u041e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043c\u043d\u0435 <a href=\"https:\/\/stackoverflow.com\/questions\/59417570\/packing-ranges-in-two-dimensions\">\u043f\u043e\u0441\u0442 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u043e\u0434\u0430\u043c\u0438 \u0440\u0430\u043d\u0435\u0435, \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u043a\u043e\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0433\u0435. \u042f \u043f\u043e\u043c\u043d\u044e, \u043a\u0430\u043a \u041f\u043e\u043b \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0436\u0435\u0441\u0442\u044b \u0440\u0443\u043a, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0435 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u043d\u043e\u0433\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u044e. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043d\u0435 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043c\u043d\u0435 \u043d\u0435\u0447\u0435\u0433\u043e \u0431\u044b\u043b\u043e \u0435\u043c\u0443 \u0442\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u044f \u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043d\u0435\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0443\u0442\u0440\u043e\u043c.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u044f \u043d\u0430\u0437\u044b\u0432\u0430\u044e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c\u0438. \u0427\u0442\u043e \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0442\u0430\u043a \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u044b\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0439 \u0438 \u0438\u043d\u0442\u0440\u0438\u0433\u0443\u044e\u0449\u0435\u0439. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u044f \u043c\u043e\u0433 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u041f\u043e\u043b \u0431\u044b\u043b \u043e\u0447\u0435\u043d\u044c \u043e\u043f\u044b\u0442\u043d\u044b\u043c \u0438 \u0443\u043c\u043d\u044b\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0441\u043f\u0443\u0441\u0442\u044f \u0433\u043e\u0434\u044b, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0435 \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440, \u043a\u0430\u043a \u043e\u043d \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0438\u0441\u043a\u0430\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0437\u043d\u0430\u0447\u0438\u0442, \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u043e \u0437\u0430\u0434\u0430\u0447\u0435 \u0434\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u041f\u043e\u043b\u0430 \u0438 \u043e \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u041f\u043e\u043b \u0441\u0430\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043b \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438.<\/p>\n<p>\u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0438 \u0441 \u041f\u043e\u043b\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u0434\u043b\u044f \u0432\u0430\u0441.\u00a0 \u042f \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/stackoverflow.com\/questions\/59417570\/packing-ranges-in-two-dimensions\">\u043f\u043e\u0441\u0442 \u041f\u043e\u043b\u0430<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0443\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0434\u0430\u0447\u0435 \u0438 \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a\u043e\u0434 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/12\/ItzikBenGanTwo-Dimensional-Interval-Packing-Challenge.zip\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\u00a0<\/h3>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f\u043c\u0438 \u0437\u0430\u043d\u044f\u0442\u0438\u0439 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Schedule, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"sql\">SET NOCOUNT ON; USE tempdb; DROP TABLE IF EXISTS dbo.Schedule; CREATE TABLE dbo.Schedule (   id         INT     NOT NULL       CONSTRAINT PK_Schedule PRIMARY KEY,   student    CHAR(3) NOT NULL,   fromdate   INT     NOT NULL,   todate     INT     NOT NULL,   fromperiod INT     NOT NULL,   toperiod   INT     NOT NULL ); INSERT INTO dbo.Schedule(id, student, fromdate, todate,  fromperiod, toperiod) VALUES     (1, 'Amy',  1,  7,  7,  9),     (2, 'Amy',  3,  9,  5,  8),      (3, 'Amy', 10, 12,  1,  3),      (4, 'Ted',  1,  5, 11, 14),     (5, 'Ted',  7, 11, 13, 16);<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0441\u0442\u0443\u0434\u0435\u043d\u0442, \u0434\u0430\u0442\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 (<code>fromdate<\/code>) \u0438 \u0434\u0430\u0442\u0430 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f (<code>todate<\/code>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 (<code>fromperiod<\/code>) \u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0430 (<code>toperiod<\/code>). \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0445 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a:<\/p>\n<pre><code class=\"sql\">SELECT student,   GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION('   + STRING_AGG(CONCAT('POLYGON((',fromdate,' ',fromperiod, ',',                                  fromdate,' ',toperiod + 1, ',',                                  todate + 1,' ',toperiod + 1,',',                                  todate + 1,' ',fromperiod,',',                                  fromdate,' ',fromperiod ,                       '))'), ',')   + ')', 0) AS shape FROM dbo.Schedule GROUP BY student;<\/code><\/pre>\n<p>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 1 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Spatial results SSMS.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1: \u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0435 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435.<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0441\u044c X \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0434\u0430\u0442, \u0430 \u043e\u0441\u044c Y \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0443 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f\u043c\u0438 1 \u0438 2 \u042d\u043c\u0438 (Amy). \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0449\u0435\u0442 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u042d\u043c\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0434\u0430\u0442\u0443 4 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434 8:<\/p>\n<pre><code class=\"sql\">SELECT id, student, fromdate, todate, fromperiod, toperiod FROM dbo.Schedule WHERE student = 'Amy'   AND 4 BETWEEN fromdate AND todate   AND 8 BETWEEN fromperiod AND toperiod;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439:<\/p>\n<pre><code>id          student fromdate    todate      fromperiod  toperiod ----------- ------- ----------- ----------- ----------- -------- 1           Amy     1           7           7           9 2           Amy     3           9           5           8<\/code><\/pre>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 (\u0434\u0430\u0442\u0430, \u043f\u0435\u0440\u0438\u043e\u0434) \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f. \u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u043d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f\u043c\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0434\u0430\u0442 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0432\u0432\u043e\u0434\u0438\u043c\u0443\u044e \u0442\u043e\u0447\u043a\u0443 (\u0434\u0430\u0442\u0430, \u043f\u0435\u0440\u0438\u043e\u0434).<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0434\u0430\u0442 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432. \u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 2 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<figure class=\"\">\n<div><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2: \u0418\u0441\u043a\u043e\u043c\u044b\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0435\u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0442\u043e \u0432\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0435 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0437\u044b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0443\u044e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0437\u044b. \u0418\u043b\u0438 \u0434\u0430\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0435\u0437\u043e\u0432. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u043c\u0438, \u0442\u043e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>student fromdate    todate      fromperiod  toperiod ------- ----------- ----------- ----------- ----------- Amy     1           2           7           9 Amy     3           7           5           9 Amy     8           9           5           8 Amy     10          12          1           3 Ted     1           5           11          14 Ted     7           11          13          16<\/code><\/pre>\n<p>\u042f \u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430 \u0440\u0430\u0431\u043e\u0442\u0443!<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438<\/h3>\n<p>\u041c\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u0442\u0430\u043f\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u043e\u0439 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 (Unpack\/Pack). \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Schedule \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0430\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0435\u0433\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0412\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u044b:<\/p>\n<pre><code class=\"sql\">SELECT id, student, fromperiod, toperiod FROM dbo.Schedule ORDER BY student, fromperiod, toperiod;<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>id          student fromperiod  toperiod ----------- ------- ----------- ----------- 3           Amy     1           3 2           Amy     5           8 1           Amy     7           9 4           Ted     11          14 5           Ted     13          16<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0443\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0447\u0435\u043d\u0438\u043a\u0430. \u0412\u043e\u0442 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430\u043c\u0438:<\/p>\n<pre><code>student fromperiod  toperiod ------- ----------- ----------- Amy     1           3 Amy     5           9 Ted     11          16<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439\/\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u043f\u0430\u043a\u0443\u0439\u0442\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435 \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/livebook.manning.com\/book\/sql-server-mvp-deep-dives\/chapter-5\/ch05ex09\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 \u043e\u0441\u0442\u0440\u043e\u0432\u043e\u0432<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443, \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0448\u0430\u0433\u0430 1. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0434\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u2014 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f integer, \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u042d\u043c\u0438 \u0441 <code>fromperiod 5<\/code> \u0438 <code>toperiod 8<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u043d \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <code>{5, 6, 7, 8}<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Azure SQL \u0438\u043b\u0438 SQL Server 2022 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>GENERATE_SERIES<\/code>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"sql\">SELECT S.id, S.student, P.value AS p FROM dbo.Schedule AS S<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-371275","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371275","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=371275"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371275\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}