{"id":402779,"date":"2024-06-29T16:43:06","date_gmt":"2024-06-29T16:43:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=402779"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=402779","title":{"rendered":"<span>\u041d\u043e\u0432\u043e\u0435 \u0432 SQL Server 2022: \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 time series (\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b)<\/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>\u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432\u00a0\u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u043a, \u043a\u0430\u043a\u00a0\u043e\u043d\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 SQL Server, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u00a0\u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438, \u0435\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u0434\u043a\u043e.<\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432: \u0446\u0435\u043d\u044b \u043d\u0430\u00a0\u0430\u043a\u0446\u0438\u0438, \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u044f \u043e\u0442\u00a0\u0434\u0430\u0442\u0447\u0438\u043a\u043e\u0432, \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 SQL Server (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0426\u041f\u0423, \u043f\u0430\u043c\u044f\u0442\u0438, \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0432\u0432\u043e\u0434\u0430\u2011\u0432\u044b\u0432\u043e\u0434\u0430 \u0438 \u0441\u0435\u0442\u0438).<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f\u00a0\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0432\u00a0\u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439 \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u00a0\u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430, \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u043e\u0432, \u0433\u0434\u0435 \u0432\u0440\u0435\u043c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u044c\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438\u00a0\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435 \u0438\u043b\u0438\u00a0\u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0432\u00a0SQL Server\u00a0\u0431\u044b\u043b\u0438 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 <a href=\"https:\/\/azure.microsoft.com\/en-ca\/products\/azure-sql\/edge\/\" rel=\"noopener noreferrer nofollow\">Azure SQL Edge<\/a>, \u0432\u0435\u0440\u0441\u0438\u0438 Microsoft SQL Server \u0434\u043b\u044f\u00a0\u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0435\u0449\u0435\u0439 (IoT), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u00a0\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b, \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432.<\/p>\n<p>\u0412\u00a0SQL Server 2022\u00a0\u0438 Azure SQL \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b\u00a0\u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u043e\u00a0\u0432\u0441\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 SQL Server. \u0412\u043d\u0435\u0441\u0435\u043d\u044b \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u00a0\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 T\u2011SQL \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f <code>NULL<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0432\u0435 \u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u0432\u0430\u043d\u043d\u044b\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GENERATE_SERIES<\/h2>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439\u00a0<strong>\u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (datetime).<\/strong>\u00a0\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0440\u044f\u0434 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0432\u043d\u044b\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0435\u043a\u0443\u043d\u0434\u0443) \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430.\u00a0\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 (tally table), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u0436\u043d\u0435\u0439 \u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439.\u00a0\u0417\u0430\u0442\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/dateadd-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">DATEADD<\/a> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439\u00a0<strong>\u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong>.<\/p>\n<p>\u0414\u043e SQL Server 2022 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0438\u0441\u0435\u043b \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>CTE<\/code>,\u00a0<code>CROSS JOIN <\/code>\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0446\u0438\u043a\u043b\u043e\u0432 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u044b\u043a\u0440\u0443\u0442\u0430\u0441\u043e\u0432 \u0432 T-SQL.\u00a0\u042d\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0438 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c\u0438, \u043d\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438, \u043d\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438, \u0437\u0430\u0442\u043e \u0431\u044b\u043b\u0438 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u044b \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0448\u0430\u0433 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b.<\/p>\n<p>\u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u00a0<code>GENERATE_SERIES<\/code> \u0432 SQL Server 2022 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0438\u0441\u0435\u043b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u043c\u0435\u0436\u0434\u0443\u00a0<strong>\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c<\/strong>\u00a0\u0438\u00a0<strong>\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c<\/strong>\u00a0\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0441 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u043c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0448\u0430\u0433\u0430\u043c\u0438 \u0432 \u0441\u0435\u0440\u0438\u0438:<\/p>\n<pre><code class=\"sql\">GENERATE_SERIES (start, stop [, step ])<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u044f\u0434 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 1 \u0434\u043e 50 \u0441 \u0448\u0430\u0433\u043e\u043c 5:<\/p>\n<pre><code class=\"sql\">SELECT value FROM GENERATE_SERIES(1, 50, 5);<\/code><\/pre>\n<pre><code class=\"bash\">value ----------- 1 6 11 16 21 26 31 36 41 46<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0432\u00a0\u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a\u00a0\u0432 <code>GENERATE_SERIES<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 <code>DATEADD<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 13:00\u00a0\u0438 14:00\u00a0\u0441\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1\u00a0\u043c\u0438\u043d\u0443\u0442\u0443:<\/p>\n<pre><code class=\"sql\">SELECT DATEADD(minute, s.value, 'Apr 10, 2023 1:00 PM') AS [Interval] FROM GENERATE_SERIES(0, 59, 1) AS s;<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f\u00a0\u0448\u0430\u0433\u0430 \u043e\u043f\u0443\u0449\u0435\u043d, \u043f\u0440\u0438\u00a0\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0440\u0430\u0432\u043d\u043e\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>GENEATE_SERIES<\/code> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u0441\u00a0\u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0432\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e\u0431\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <strong>start<\/strong>, <strong>stop<\/strong> \u0438 <strong>step<\/strong>\u00a0\u0431\u044b\u043b\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0415\u0441\u043b\u0438 <strong>start<\/strong> \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c <strong>stop<\/strong>, \u0430 <strong>step<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u0432\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u044f\u0434 \u0443\u0431\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 <strong>start<\/strong> \u0431\u043e\u043b\u044c\u0448\u0435 <strong>stop<\/strong> \u0438 <strong>step<\/strong> \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0443\u0441\u0442\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043b\u044f\u00a0\u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>GENERATE_SERIES<\/code> \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u00a0\u043d\u0438\u0436\u0435 160.<\/p>\n<h2>\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 DATE_BUCKET<\/h2>\n<p>\u0414\u043b\u044f\u00a0\u0437\u0430\u0434\u0430\u0447 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438\u00a0\u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u0430\u0445 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u0432\u0438\u0434\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u0430\u0436\u0434\u0443\u044e \u043c\u0438\u043d\u0443\u0442\u0443 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c \u0437\u0430 15-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043b\u0438\u00a0\u0434\u0430\u0436\u0435 \u0447\u0430\u0441\u043e\u0432\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b. \u0425\u043e\u0442\u044f \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>GENERATE_SERIES<\/code> \u0438 <code>DATEADD<\/code>, \u043d\u0443\u0436\u0435\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u00a0\u043a\u0430\u043a\u043e\u043c\u0443 \u0438\u0437\u00a0\u043d\u0438\u0445 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u043e\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>DATE_BUCKET<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>\u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 <strong>\u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong> \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430, \u0438 \u0441\u00a0\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0434\u043b\u044f\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\/origin), \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b. \u0415\u0441\u043b\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d, \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1\u00a0\u044f\u043d\u0432\u0430\u0440\u044f 1900\u00a0\u0433\u043e\u0434\u0430:<\/p>\n<p><code>DATE_BUCKET (datepart, number, date, origin)<\/code><\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043d\u0430 10 \u0434\u0435\u043a\u0430\u0431\u0440\u044f 2022 \u0433. \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0434\u0430\u0442\u044b \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 1 \u0438 \u0441 \u0442\u043e\u0447\u043a\u043e\u0439 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u043d\u0430 1 \u044f\u043d\u0432\u0430\u0440\u044f 2022 \u0433.:<\/p>\n<pre><code class=\"sql\">DECLARE @date DATETIME = 'Dec 10, 2022 12:05 PM'; DECLARE @origin DATETIME = 'Jan 1, 2022 12:00 AM';  SELECT 'Now' AS [BucketName], @date AS [DateBucketValue] UNION ALL SELECT 'Year', DATE_BUCKET (YEAR, 1, @date, @origin) UNION ALL SELECT 'Quarter', DATE_BUCKET (QUARTER, 1, @date, @origin) UNION ALL SELECT 'Month', DATE_BUCKET (MONTH, 1, @date, @origin) UNION ALL SELECT 'Week', DATE_BUCKET (WEEK, 1, @date, @origin) UNION ALL SELECT 'Day', DATE_BUCKET (DAY, 1, @date, @origin) UNION ALL SELECT 'Hour', DATE_BUCKET (HOUR, 1, @date, @origin) UNION ALL SELECT 'Minutes', DATE_BUCKET (MINUTE, 1, @date, @origin) UNION ALL SELECT 'Seconds', DATE_BUCKET (SECOND, 1, @date, @origin)<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0434\u0430\u0442 \u0434\u043b\u044f \u043d\u0435\u0434\u0435\u043b\u0438: \u0434\u0430\u0442\u044b\u00a0<code>SELECT 'Week', DATE_BUCKET (WEEK, 1, @date, @origin)<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 10 \u0434\u0435\u043a\u0430\u0431\u0440\u044f 2022 \u0433., \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0443\u0431\u0431\u043e\u0442\u0443.\u00a0\u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0434\u0430\u0442\u0430 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 (1 \u044f\u043d\u0432\u0430\u0440\u044f 2022 \u0433.) \u0442\u0430\u043a\u0436\u0435 \u0441\u0443\u0431\u0431\u043e\u0442\u0430\u00a0(\u043e\u0441\u043e\u0431\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u0442\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e = 1 \u044f\u043d\u0432\u0430\u0440\u044f 1900 \u0433. \u2014 \u044d\u0442\u043e \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a).\u00a0\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0438 \u043d\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b\u00a0\u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432 \u0432\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u0442\u0430\u043a\u0443\u044e \u0434\u0430\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435.<\/p>\n<p><code>DATE_BUCKET<\/code> \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u00a0\u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 1. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 5-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043b\u0438 15-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b.<\/p>\n<pre><code class=\"sql\">SELECT 'Now' AS [BucketName], GETDATE() AS [BucketDate] UNION ALL SELECT '5 Minute Buckets', DATE_BUCKET (MINUTE, 5, GETDATE()) UNION ALL SELECT 'Quarter Hour', DATE_BUCKET (MINUTE, 15, GETDATE());<\/code><\/pre>\n<p><code>DATE_BUCKET<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043c\u0435\u0442\u043a\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<h2>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0441 FIRST_VALUE \u0438 LAST_VALUE<\/h2>\n<p><code>FIRST_VALUE <\/code>\u0438 <code>LAST_VALUE <\/code>\u043d\u0435\u00a0\u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u00a0SQL Server 2022; \u0447\u0442\u043e <em>\u043d\u043e\u0432\u043e\u0433\u043e<\/em>, \u0442\u0430\u043a \u044d\u0442\u043e \u0442\u043e, \u043a\u0430\u043a\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>NULL<\/code>. \u0412\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 SQL Server \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>NULL<\/code> \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438\u0441\u044c.<\/p>\n<p>\u041f\u0440\u0438\u00a0\u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u044f\u0434\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438. \u0412\u00a0\u0438\u0434\u0435\u0430\u043b\u0435 \u043e\u043d\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u041f\u0440\u0438\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>FIRST_VALUE<\/code> \u0438 <code>LAST_VALUE<\/code> \u0434\u043b\u044f\u00a0\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0443, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<code> NULL<\/code> \u043d\u0435\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>\u0412\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0447\u0438\u043a\u0430, \u0441\u043d\u044f\u0442\u044b\u0435 \u0441 15-\u0441\u0435\u043a\u0443\u043d\u0434\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432. \u041f\u0440\u0438\u00a0\u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1\u00a0\u043c\u0438\u043d\u0443\u0442\u0443 (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>DATE_BUCKET<\/code>), \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>FIRST_VALUE<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c <code>NULL<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT [timestamp] \u00a0\u00a0 , DATE_BUCKET(MINUTE, 1, [timestamp]) AS [timestamp_bucket] \u00a0\u00a0 , SensorReading \u00a0\u00a0 , FIRST_VALUE (SensorReading) OVER (  PARTITION BY DATE_BUCKET(MINUTE, 1, [timestamp])  ORDER BY [timestamp]  ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS [Default (RESPECT NULLS)] FROM MachineTelemetry ORDER BY [timestamp];<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>FIRST_VALUE<\/code> \u0438\u00a0<code>LAST_VALUE<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 SQL Server 2022 \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 (<code>IGNORE NULLS<\/code> \u0438\u043b\u0438\u00a0<code>RESPECT NULLS<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u00a0<code>NULL<\/code>:<\/p>\n<pre><code class=\"sql\">FIRST_VALUE ( [scalar_expression ]   )\u00a0 [ IGNORE NULLS | RESPECT NULLS ] \u00a0\u00a0\u00a0\u00a0OVER ( [   partition_by_clause ] order_by_clause [ rows_range_clause ] )<\/code><\/pre>\n<p><code>RESPECT NULLS<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>NULL<\/code> \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438.\u00a0\u0423\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u00a0<code>IGNORE NULLS<\/code> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442\u00a0\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>NULL<\/code>.<\/p>\n<pre><code class=\"sql\">SELECT [timestamp] \u00a0\u00a0 , DATE_BUCKET(MINUTE, 1, [timestamp]) AS [timestamp_bucket] \u00a0\u00a0 , SensorReading \u00a0\u00a0 , FIRST_VALUE (SensorReading) IGNORE NULLS OVER (  PARTITION BY DATE_BUCKET(MINUTE, 1, [timestamp])  ORDER BY [timestamp]  ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS [Default (RESPECT NULLS)] FROM MachineTelemetry ORDER BY [timestamp];<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>IGNORE NULLS<\/code> \u0438\u00a0<code>RESPECT NULLS<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<h3>Microsoft Learn<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/generate-series-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">GENERATE_SERIES<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/date-bucket-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">DATE_BUCKET<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/first-value-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">FIRST_VALUE<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/last-value-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">LAST_VALUE<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 GitHub<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/microsoft\/bobsql\/tree\/master\/demos\/sqlserver2022\/tsql\/timeseries\" rel=\"noopener noreferrer nofollow\">Time Series T-SQL functions in SQL Server 2022<\/a><\/p>\n<\/li>\n<\/ul>\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\/731772\/\"> https:\/\/habr.com\/ru\/articles\/731772\/<\/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>\u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432\u00a0\u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u043a, \u043a\u0430\u043a\u00a0\u043e\u043d\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 SQL Server, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u00a0\u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438, \u0435\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u0434\u043a\u043e.<\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432: \u0446\u0435\u043d\u044b \u043d\u0430\u00a0\u0430\u043a\u0446\u0438\u0438, \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u044f \u043e\u0442\u00a0\u0434\u0430\u0442\u0447\u0438\u043a\u043e\u0432, \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 SQL Server (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0426\u041f\u0423, \u043f\u0430\u043c\u044f\u0442\u0438, \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0432\u0432\u043e\u0434\u0430\u2011\u0432\u044b\u0432\u043e\u0434\u0430 \u0438 \u0441\u0435\u0442\u0438).<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f\u00a0\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0432\u00a0\u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439 \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u00a0\u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430, \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0447\u0435\u0442\u043e\u0432, \u0433\u0434\u0435 \u0432\u0440\u0435\u043c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u044c\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438\u00a0\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435 \u0438\u043b\u0438\u00a0\u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0432\u00a0SQL Server\u00a0\u0431\u044b\u043b\u0438 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 <a href=\"https:\/\/azure.microsoft.com\/en-ca\/products\/azure-sql\/edge\/\" rel=\"noopener noreferrer nofollow\">Azure SQL Edge<\/a>, \u0432\u0435\u0440\u0441\u0438\u0438 Microsoft SQL Server \u0434\u043b\u044f\u00a0\u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0435\u0449\u0435\u0439 (IoT), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u00a0\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b, \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432.<\/p>\n<p>\u0412\u00a0SQL Server 2022\u00a0\u0438 Azure SQL \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b\u00a0\u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u043e\u00a0\u0432\u0441\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 SQL Server. \u0412\u043d\u0435\u0441\u0435\u043d\u044b \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u00a0\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 T\u2011SQL \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f <code>NULL<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0432\u0435 \u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u0432\u0430\u043d\u043d\u044b\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GENERATE_SERIES<\/h2>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439\u00a0<strong>\u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (datetime).<\/strong>\u00a0\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0440\u044f\u0434 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0432\u043d\u044b\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0435\u043a\u0443\u043d\u0434\u0443) \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430.\u00a0\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 (tally table), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u0436\u043d\u0435\u0439 \u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439.\u00a0\u0417\u0430\u0442\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/dateadd-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">DATEADD<\/a> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439\u00a0<strong>\u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong>.<\/p>\n<p>\u0414\u043e SQL Server 2022 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0438\u0441\u0435\u043b \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>CTE<\/code>,\u00a0<code>CROSS JOIN <\/code>\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0446\u0438\u043a\u043b\u043e\u0432 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u044b\u043a\u0440\u0443\u0442\u0430\u0441\u043e\u0432 \u0432 T-SQL.\u00a0\u042d\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0438 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c\u0438, \u043d\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438, \u043d\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438, \u0437\u0430\u0442\u043e \u0431\u044b\u043b\u0438 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u044b \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0448\u0430\u0433 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u043b \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b.<\/p>\n<p>\u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u00a0<code>GENERATE_SERIES<\/code> \u0432 SQL Server 2022 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0447\u0438\u0441\u0435\u043b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u043c\u0435\u0436\u0434\u0443\u00a0<strong>\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c<\/strong>\u00a0\u0438\u00a0<strong>\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c<\/strong>\u00a0\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0441 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u043c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0448\u0430\u0433\u0430\u043c\u0438 \u0432 \u0441\u0435\u0440\u0438\u0438:<\/p>\n<pre><code class=\"sql\">GENERATE_SERIES (start, stop [, step ])<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u044f\u0434 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 1 \u0434\u043e 50 \u0441 \u0448\u0430\u0433\u043e\u043c 5:<\/p>\n<pre><code class=\"sql\">SELECT value FROM GENERATE_SERIES(1, 50, 5);<\/code><\/pre>\n<pre><code class=\"bash\">value ----------- 1 6 11 16 21 26 31 36 41 46<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0432\u00a0\u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a\u00a0\u0432 <code>GENERATE_SERIES<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 <code>DATEADD<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 13:00\u00a0\u0438 14:00\u00a0\u0441\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1\u00a0\u043c\u0438\u043d\u0443\u0442\u0443:<\/p>\n<pre><code class=\"sql\">SELECT DATEADD(minute, s.value, 'Apr 10, 2023 1:00 PM') AS [Interval] FROM GENERATE_SERIES(0, 59, 1) AS s;<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f\u00a0\u0448\u0430\u0433\u0430 \u043e\u043f\u0443\u0449\u0435\u043d, \u043f\u0440\u0438\u00a0\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0440\u0430\u0432\u043d\u043e\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>GENEATE_SERIES<\/code> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u0441\u00a0\u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0432\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e\u0431\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <strong>start<\/strong>, <strong>stop<\/strong> \u0438 <strong>step<\/strong>\u00a0\u0431\u044b\u043b\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0415\u0441\u043b\u0438 <strong>start<\/strong> \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c <strong>stop<\/strong>, \u0430 <strong>step<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u0432\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u044f\u0434 \u0443\u0431\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 <strong>start<\/strong> \u0431\u043e\u043b\u044c\u0448\u0435 <strong>stop<\/strong> \u0438 <strong>step<\/strong> \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0443\u0441\u0442\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043b\u044f\u00a0\u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>GENERATE_SERIES<\/code> \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u00a0\u043d\u0438\u0436\u0435 160.<\/p>\n<h2>\u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0441 DATE_BUCKET<\/h2>\n<p>\u0414\u043b\u044f\u00a0\u0437\u0430\u0434\u0430\u0447 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438\u00a0\u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u0430\u0445 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u0432\u0438\u0434\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u0430\u0436\u0434\u0443\u044e \u043c\u0438\u043d\u0443\u0442\u0443 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c \u0437\u0430 15-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043b\u0438\u00a0\u0434\u0430\u0436\u0435 \u0447\u0430\u0441\u043e\u0432\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b. \u0425\u043e\u0442\u044f \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b <code>GENERATE_SERIES<\/code> \u0438 <code>DATEADD<\/code>, \u043d\u0443\u0436\u0435\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u00a0\u043a\u0430\u043a\u043e\u043c\u0443 \u0438\u0437\u00a0\u043d\u0438\u0445 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u043e\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>DATE_BUCKET<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>\u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\/\u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 <strong>\u0434\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/strong> \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430, \u0438 \u0441\u00a0\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0434\u043b\u044f\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\/origin), \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b. \u0415\u0441\u043b\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d, \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1\u00a0\u044f\u043d\u0432\u0430\u0440\u044f 1900\u00a0\u0433\u043e\u0434\u0430:<\/p>\n<p><code>DATE_BUCKET (datepart, number, date, origin)<\/code><\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043d\u0430 10 \u0434\u0435\u043a\u0430\u0431\u0440\u044f 2022 \u0433. \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0434\u0430\u0442\u044b \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 1 \u0438 \u0441 \u0442\u043e\u0447\u043a\u043e\u0439 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u043d\u0430 1 \u044f\u043d\u0432\u0430\u0440\u044f 2022 \u0433.:<\/p>\n<pre><code class=\"sql\">DECLARE @date DATETIME = 'Dec 10, 2022 12:05 PM'; DECLARE @origin DATETIME = 'Jan 1, 2022 12:00 AM';  SELECT 'Now' AS [BucketName], @date AS [DateBucketValue] UNION ALL SELECT 'Year', DATE_BUCKET (YEAR, 1, @date, @origin) UNION ALL SELECT 'Quarter', DATE_BUCKET (QUARTER, 1, @date, @origin) UNION ALL SELECT 'Month', DATE_BUCKET (MONTH, 1, @date, @origin) UNION ALL SELECT 'Week', DATE_BUCKET (WEEK, 1, @date, @origin) UNION ALL SELECT 'Day', DATE_BUCKET (DAY, 1, @date, @origin) UNION ALL SELECT 'Hour', DATE_BUCKET (HOUR, 1, @date, @origin) UNION ALL SELECT 'Minutes', DATE_BUCKET (MINUTE, 1, @date, @origin) UNION ALL SELECT 'Seconds', DATE_BUCKET (SECOND, 1, @date, @origin)<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0434\u0430\u0442 \u0434\u043b\u044f \u043d\u0435\u0434\u0435\u043b\u0438: \u0434\u0430\u0442\u044b\u00a0<code>SELECT 'Week', DATE_BUCKET (WEEK, 1, @date, @origin)<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 10 \u0434\u0435\u043a\u0430\u0431\u0440\u044f 2022 \u0433., \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0443\u0431\u0431\u043e\u0442\u0443.\u00a0\u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u0434\u0430\u0442\u0430 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 (1 \u044f\u043d\u0432\u0430\u0440\u044f 2022 \u0433.) \u0442\u0430\u043a\u0436\u0435 \u0441\u0443\u0431\u0431\u043e\u0442\u0430\u00a0(\u043e\u0441\u043e\u0431\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u0442\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e = 1 \u044f\u043d\u0432\u0430\u0440\u044f 1900 \u0433. \u2014 \u044d\u0442\u043e \u043f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a).\u00a0\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0438 \u043d\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b\u00a0\u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432 \u0432\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0451\u0442\u0430 \u0442\u0430\u043a\u0443\u044e \u0434\u0430\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435.<\/p>\n<p><code>DATE_BUCKET<\/code> \u0431\u044b\u0432\u0430\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u00a0\u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 1. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 5-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043b\u0438 15-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b.<\/p>\n<pre><code class=\"sql\">SELECT 'Now' AS [BucketName], GETDATE() AS [BucketDate] UNION ALL SELECT '5 Minute Buckets', DATE_BUCKET (MINUTE, 5, GETDATE()) UNION ALL SELECT 'Quarter Hour', DATE_BUCKET (MINUTE, 15, GETDATE());<\/code><\/pre>\n<p><code>DATE_BUCKET<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043c\u0435\u0442\u043a\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<h2>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0441 FIRST_VALUE \u0438 LAST_VALUE<\/h2>\n<p><code>FIRST_VALUE <\/code>\u0438 <code>LAST_VALUE <\/code>\u043d\u0435\u00a0\u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u00a0SQL Server 2022; \u0447\u0442\u043e <em>\u043d\u043e\u0432\u043e\u0433\u043e<\/em>, \u0442\u0430\u043a \u044d\u0442\u043e \u0442\u043e, \u043a\u0430\u043a\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>NULL<\/code>. \u0412\u00a0\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 SQL Server \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>NULL<\/code> \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438\u0441\u044c.<\/p>\n<p>\u041f\u0440\u0438\u00a0\u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u044f\u0434\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0438. \u0412\u00a0\u0438\u0434\u0435\u0430\u043b\u0435 \u043e\u043d\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u041f\u0440\u0438\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>FIRST_VALUE<\/code> \u0438 <code>LAST_VALUE<\/code> \u0434\u043b\u044f\u00a0\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0443, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<code> NULL<\/code> \u043d\u0435\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>\u0412\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0447\u0438\u043a\u0430, \u0441\u043d\u044f\u0442\u044b\u0435 \u0441 15-\u0441\u0435\u043a\u0443\u043d\u0434\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u043c\u0438, \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432. \u041f\u0440\u0438\u00a0\u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u00a0\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1\u00a0\u043c\u0438\u043d\u0443\u0442\u0443 (\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>DATE_BUCKET<\/code>), \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>FIRST_VALUE<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c <code>NULL<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT [timestamp] \u00a0\u00a0 , DATE_BUCKET(MINUTE, 1, [timestamp]) AS [timestamp_bucket] \u00a0\u00a0 , SensorReading \u00a0\u00a0 , FIRST_VALUE (SensorReading) OVER (  PARTITION BY DATE_BUCKET(MINUTE, 1, [timestamp])  ORDER BY [timestamp]  ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS [Default (RESPECT NULLS)] FROM MachineTelemetry ORDER BY [timestamp];<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>FIRST_VALUE<\/code> \u0438\u00a0<code>LAST_VALUE<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 SQL Server 2022 \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 (<code>IGNORE NULLS<\/code> \u0438\u043b\u0438\u00a0<code>RESPECT NULLS<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u00a0<code>NULL<\/code>:<\/p>\n<pre><code class=\"sql\">FIRST_VALUE ( [scalar_expression ]   )\u00a0 [ IGNORE NULLS | RESPECT NULLS ] \u00a0\u00a0\u00a0\u00a0OVER ( [   partition_by_clause ] order_by_clause [ rows_range_clause ] )<\/code><\/pre>\n<p><code>RESPECT NULLS<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>NULL<\/code> \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438.\u00a0\u0423\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u00a0<code>IGNORE NULLS<\/code> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442\u00a0\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>NULL<\/code>.<\/p>\n<pre><code class=\"sql\">SELECT [timestamp] \u00a0\u00a0 , DATE_BUCKET(MINUTE, 1, [timestamp]) AS [timestamp_bucket] \u00a0\u00a0 , SensorReading \u00a0\u00a0 , FIRST_VALUE (SensorReading) IGNORE NULLS OVER (  PARTITION BY DATE_BUCKET(MINUTE, 1, [timestamp])  ORDER BY [timestamp]  ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS [Default (RESPECT NULLS)] FROM MachineTelemetry ORDER BY [timestamp];<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>IGNORE NULLS<\/code> \u0438\u00a0<code>RESPECT NULLS<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<h3>Microsoft Learn<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/generate-series-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">GENERATE_SERIES<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/date-bucket-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">DATE_BUCKET<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/first-value-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">FIRST_VALUE<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/last-value-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">LAST_VALUE<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 GitHub<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/microsoft\/bobsql\/tree\/master\/demos\/sqlserver2022\/tsql\/timeseries\" rel=\"noopener noreferrer nofollow\">Time Series T-SQL functions in SQL Server 2022<\/a><\/p>\n<\/li>\n<\/ul>\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\/731772\/\"> https:\/\/habr.com\/ru\/articles\/731772\/<\/a><br \/><\/br><\/br><\/p>\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-402779","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402779","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=402779"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402779\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}