{"id":287855,"date":"2018-08-16T14:17:59","date_gmt":"2018-08-16T10:17:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287855"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287855","title":{"rendered":"\u041f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u043e\u0432 (\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b, \u0444\u043e\u0440\u0435\u043a\u0441, \u0431\u0438\u0440\u0436\u0438)"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418757\/\" class=\"post__text post__text-html js-mediator-article\">\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u0438\u0440\u043e\u0432\u043e\u043a \u0440\u044b\u043d\u043a\u0430 \u0424\u043e\u0440\u0435\u043a\u0441 (\u0442\u043e\u0447\u043d\u0435\u0435, \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u043e\u0432).<\/p>\n<p>  \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438: \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0432 \u0442\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<ul>\n<li>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 (\u043a\u043e\u0434 \u043f\u0430\u0440\u044b USDEUR \u0438 \u043f\u0440.),<\/li>\n<li>\u0414\u0430\u0442\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 unix time,<\/li>\n<li>Open value (\u0446\u0435\u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0434\u0435\u043b\u043a\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435),<\/li>\n<li>High value (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430),<\/li>\n<li>Low value (\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430),<\/li>\n<li>Close value (\u0446\u0435\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0434\u0435\u043b\u043a\u0438),<\/li>\n<li>Volume (\u0433\u0440\u043e\u043c\u043a\u043e\u0441\u0442\u044c, \u0438\u043b\u0438 \u043e\u0431\u044a\u0451\u043c \u0441\u0434\u0435\u043b\u043a\u0438).<\/li>\n<\/ul>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442 \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: 5 \u0441\u0435\u043a, 15 \u0441\u0435\u043a, 1 \u043c\u0438\u043d, 5 \u043c\u0438\u043d, 15 \u043c\u0438\u043d, \u0438 \u0442.\u0434.<\/p>\n<p>  \u041e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 OHLC, \u0438\u043b\u0438 OHLCV (Open, High, Low, Close, Volume). \u041e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u043f\u043e \u043d\u0435\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u00ab\u042f\u043f\u043e\u043d\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438\u00bb.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/by\/ws\/8u\/byws8uaklvxydw8d2wqkqhpb1ni.png\" alt=\"image\"\/><\/div>\n<p>  \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043a\u0430\u043a\u0438\u0435 \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u0442\u044c (\u0443\u043a\u0440\u0443\u043f\u043d\u044f\u0442\u044c) \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0438\u043c\u043d\u0435\u0433\u043e \u0441\u043a\u0430\u0447\u043a\u0430 \u0446\u0435\u043d\u044b \u0431\u0438\u0442\u043a\u043e\u0438\u043d\u0430, \u0430 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0432\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435 \u0433\u0440\u0430\u0444\u0438\u043a \u00ab\u042f\u043f\u043e\u043d\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438\u00bb (\u0432 MS Excel \u0442\u0430\u043a\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c). \u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0434\u043b\u044f \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u0430 \u00ab1 \u043c\u0435\u0441\u044f\u0446\u00bb, \u0434\u043b\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u00abbitstampUSD\u00bb. \u0411\u0435\u043b\u043e\u0435 \u0442\u0435\u043b\u043e \u0441\u0432\u0435\u0447\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0440\u043e\u0441\u0442 \u0446\u0435\u043d\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435, \u0447\u0451\u0440\u043d\u043e\u0435&nbsp;&mdash; \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u044b, \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0438 \u043d\u0438\u0436\u043d\u0438\u0435 \u0444\u0438\u0442\u0438\u043b\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u043b\u0438\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435. \u0424\u043e\u043d&nbsp;&mdash; \u043e\u0431\u044a\u0451\u043c \u0441\u0434\u0435\u043b\u043e\u043a. \u0425\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0434\u0435\u043a\u0430\u0431\u0440\u0435 2017 \u0446\u0435\u043d\u0430 \u0432\u043f\u043b\u043e\u0442\u043d\u0443\u044e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043b\u0430\u0441\u044c \u043a \u043e\u0442\u043c\u0435\u0442\u043a\u0435 20\u041a.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0434\u0432\u0438\u0436\u043a\u043e\u0432 \u0411\u0414, \u0434\u043b\u044f Oracle \u0438 MS SQL, \u0447\u0442\u043e, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u043e\u0434\u0435, \u0434\u0430\u0441\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 (\u043e\u0431\u043e\u0431\u0449\u0430\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c).<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0422\u043e\u0433\u0434\u0430 \u044f \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c: \u0440\u0430\u0441\u0447\u0451\u0442 \u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439&nbsp;&mdash; \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439. \u041d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u043b\u043e, \u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u044f \u0437\u0430\u043a\u0440\u044b\u043b.<\/p>\n<p>  \u041d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u0443 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c&nbsp;&mdash; \u0435\u0433\u043e \u0442\u0440\u0443\u0434\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441\u0440\u0430\u0437\u0443:<\/p>\n<ul>\n<li>\u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0443\u0441\u0442\u0430 \u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0445,<\/li>\n<li>\u0438 \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438.<\/li>\n<\/ul>\n<p>  \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0430 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043a \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043c\u0435\u043d\u044c\u0448\u0443\u044e, \u0430 \u043d\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u0412 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0431\u043e\u043b\u044c\u0448\u0430\u044f\/\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0430\u044f, \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0434\u0435\u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f\u043c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0438\u043c\u043d\u0435\u0433\u043e \u0441\u043a\u0430\u0447\u043a\u0430 \u0446\u0435\u043d\u044b \u0431\u0438\u0442\u043a\u043e\u0438\u043d\u0430.<\/p>\n<p>  \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043e\u043d\u043b\u0430\u0439\u043d-\u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 github \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u043d\u0438\u0437\u0443 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  \u041a \u0434\u0435\u043b\u0443\u2026 \u041c\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u0430\u0441\u0430\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441 \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u0430 \u00ab1 \u0441\u0435\u043a\u00bb \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u044f \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441 \u0443\u0440\u043e\u0432\u043d\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 (\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u043b\u044f STOCK_NAME, UT, ID, APRICE, AVOLUME). \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0434\u0430\u0451\u0442 \u0441\u0430\u0439\u0442 bitcoincharts.com.<br \/>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 c \u0443\u0440\u043e\u0432\u043d\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0434\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u00ab1 \u0441\u0435\u043a\u00bb \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043b\u0435\u0433\u043a\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441 \u0443\u0440\u043e\u0432\u043d\u044f \u00ab1 \u0441\u0435\u043a\u00bb \u0434\u043e \u0432\u0435\u0440\u0445\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439):<\/p>\n<p>  <b>\u041d\u0430 Oracle:<\/b><\/p>\n<pre><code class=\"sql\">select        1                                                    as STRIPE_ID      , STOCK_NAME      , TRUNC_UT (UT, 1)                                     as UT      , avg (APRICE) keep (dense_rank first order by UT, ID) as AOPEN      , max (APRICE)                                         as AHIGH      , min (APRICE)                                         as ALOW      , avg (APRICE) keep (dense_rank last  order by UT, ID) as ACLOSE      , sum (AVOLUME)                                        as AVOLUME      , sum (APRICE * AVOLUME)                               as AAMOUNT      , count (*)                                            as ACOUNT from TRANSACTIONS_RAW group by STOCK_NAME, TRUNC_UT (UT, 1); <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <i>avg () keep (dense_rank first order by UT, ID)<\/i> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a: \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 GROUP BY, \u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445. \u0412 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e UT \u0438 ID, \u043d\u0443\u043c\u0435\u0440\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <i>dense_rank<\/i>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f first, \u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430, \u0433\u0434\u0435 <i>dense_rank<\/i> \u0432\u0435\u0440\u043d\u0443\u043b\u0430 1 (\u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435)&nbsp;&mdash; \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e UT, ID, \u0435\u0441\u043b\u0438 \u0431\u044b \u0442\u0430\u043c \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a, \u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0440\u0435\u0434\u043d\u0435\u0435. \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 (\u0438\u0437-\u0437\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 ID), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a AOPEN. \u041d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <i>first<\/i> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u0435.<\/p>\n<p>  <b>\u041d\u0430 MS SQL<\/b><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <i>first\/last<\/i> (\u0435\u0441\u0442\u044c <i>first_value\/last_value<\/i>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u043e). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u0430\u043c\u0443 \u0441 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u043d\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0438\u0436\u0435 \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 <i>dbo.THINNING_HABR_CALC<\/i>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u0435\u0437 <i>first\/last<\/i> \u043e\u043d \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u044f\u0449\u0435\u043d, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>  \u041a\u0430\u043a \u0436\u0435 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c? (\u0417\u0434\u0435\u0441\u044c, \u043f\u043e\u0434 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043c \u00ab\u043e\u0434\u0438\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u00bb \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d, \u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0446\u0438\u043a\u043b\u043e\u0432, \u00ab\u0434\u0451\u0440\u0433\u0430\u044e\u0449\u0438\u0445\u00bb \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435.)<\/p>\n<p>  \u042f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044e \u0432\u0441\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u043d\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<ol>\n<li>SIMP (simple, \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435),<\/li>\n<li>CALC (calculate, \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u0445\u043d\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439),<\/li>\n<li>CHIN (china way, \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u0440\u0430\u0437\u0443),<\/li>\n<li>UDAF (user-defined aggregate function),<\/li>\n<li>PPTF (pipelined and parallel table function, \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u0432\u0441\u0435\u0433\u043e \u0441 \u0434\u0432\u0443\u043c\u044f \u043a\u0443\u0440\u0441\u043e\u0440\u0430\u043c\u0438, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0434\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 SQL),<\/li>\n<li>MODE (model, \u0444\u0440\u0430\u0437\u0430 MODEL),<\/li>\n<li>\u0438 IDEA (ideal, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441).<\/li>\n<\/ol>\n<p>  \u0417\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0442\u043e\u0442 \u0440\u0435\u0434\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 PPTF \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043d\u0430 Oracle.<\/p>\n<p>  \u0421\u043a\u0430\u0447\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0441 \u0441\u0430\u0439\u0442\u0430 <a href=\"http:\/\/api.bitcoincharts.com\/v1\/csv\">http:\/\/api.bitcoincharts.com\/v1\/csv<\/a><br \/>  \u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b kraken*. \u0424\u0430\u0439\u043b\u044b localbtc* \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0448\u0443\u043c\u043b\u0435\u043d\u044b&nbsp;&mdash; \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043e\u0442\u0432\u043b\u0435\u043a\u0430\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043d\u0435\u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u0446\u0435\u043d\u0430\u043c\u0438. \u0412\u0441\u0435 kraken* \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 31M \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u0442\u0442\u0443\u0434\u0430 krakenEUR, \u0442\u043e\u0433\u0434\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f 11\u041c. \u042d\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u044a\u0451\u043c \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 Powershell \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043b\u044f SQLLDR \u0434\u043b\u044f Oracle \u0438 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0434\u043b\u044f MSSQL.<\/p>\n<pre><code> # MODIFY PARAMETERS THERE $OracleConnectString = &quot;THINNING\/aaa@P-ORA11\/ORCL&quot; # For Oracle $PathToCSV = &quot;Z:\\10&quot; # without trailing slash   $filenames = Get-ChildItem -name *.csv  Remove-Item *.ctl -ErrorAction SilentlyContinue Remove-Item *.log -ErrorAction SilentlyContinue Remove-Item *.bad -ErrorAction SilentlyContinue Remove-Item *.dsc -ErrorAction SilentlyContinue Remove-Item LoadData-Oracle.bat -ErrorAction SilentlyContinue Remove-Item LoadData-MSSQL.sql -ErrorAction SilentlyContinue  ForEach ($FilenameExt in $Filenames) { \tWrite-Host &quot;Processing file: &quot;$FilenameExt \t$StockName = $FilenameExt.substring(1, $FilenameExt.Length-5) \t$FilenameCtl = '.'+$Stockname+'.ctl'         Add-Content -Path $FilenameCtl -Value &quot;OPTIONS (DIRECT=TRUE, PARALLEL=FALSE, ROWS=1000000, SKIP_INDEX_MAINTENANCE=Y)&quot;         Add-Content -Path $FilenameCtl -Value &quot;UNRECOVERABLE&quot;         Add-Content -Path $FilenameCtl -Value &quot;LOAD DATA&quot;         Add-Content -Path $FilenameCtl -Value &quot;INFILE '.$StockName.csv'&quot;         Add-Content -Path $FilenameCtl -Value &quot;BADFILE '.$StockName.bad'&quot;         Add-Content -Path $FilenameCtl -Value &quot;DISCARDFILE '.$StockName.dsc'&quot;         Add-Content -Path $FilenameCtl -Value &quot;INTO TABLE TRANSACTIONS_RAW&quot;         Add-Content -Path $FilenameCtl -Value &quot;APPEND&quot;         Add-Content -Path $FilenameCtl -Value &quot;FIELDS TERMINATED BY ','&quot;         Add-Content -Path $FilenameCtl -Value &quot;(ID SEQUENCE (0), STOCK_NAME constant '$StockName', UT, APRICE, AVOLUME)&quot;         Add-Content -Path LoadData-Oracle.bat -Value &quot;sqlldr $OracleConnectString control=$FilenameCtl&quot;          Add-Content -Path LoadData-MSSQL.sql -Value &quot;insert into TRANSACTIONS_RAW (STOCK_NAME, UT, APRICE, AVOLUME)&quot;         Add-Content -Path LoadData-MSSQL.sql -Value &quot;select '$StockName' as STOCK_NAME, UT, APRICE, AVOLUME&quot;         Add-Content -Path LoadData-MSSQL.sql -Value &quot;from openrowset (bulk '$PathToCSV\\$FilenameExt', formatfile = '$PathToCSV\\format_mssql.bcp') as T1;&quot;         Add-Content -Path LoadData-MSSQL.sql -Value &quot;&quot; } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043d\u0430 Oracle.<\/p>\n<pre><code class=\"sql\">create table TRANSACTIONS_RAW (       ID            number not null     , STOCK_NAME    varchar2 (32)     , UT            number not null     , APRICE        number not null     , AVOLUME       number not null) pctfree 0 parallel 4 nologging; <\/code><\/pre>\n<p>  \u041d\u0430 Oracle \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0444\u0430\u0439\u043b <i>LoadData-Oracle.bat<\/i>, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 Powershell.<\/p>\n<p>  \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 11M \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0432 8 \u0444\u0430\u0439\u043b\u0430\u0445 kraken* (\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0444\u0430\u0439\u043b EUR) \u0437\u0430\u043d\u044f\u043b\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 1 \u043c\u0438\u043d\u0443\u0442\u044b.<\/p>\n<p>  \u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0443\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u0442 \u0434\u043e \u0433\u0440\u0430\u043d\u0438\u0446 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432:<\/p>\n<pre><code class=\"sql\">create or replace function TRUNC_UT (p_UT number, p_StripeTypeId number) return number deterministic is begin     return     case p_StripeTypeId     when 1  then trunc (p_UT \/ 1) * 1     when 2  then trunc (p_UT \/ 10) * 10     when 3  then trunc (p_UT \/ 60) * 60     when 4  then trunc (p_UT \/ 600) * 600     when 5  then trunc (p_UT \/ 3600) * 3600     when 6  then trunc (p_UT \/ ( 4 * 3600)) * ( 4 * 3600)     when 7  then trunc (p_UT \/ (24 * 3600)) * (24 * 3600)     when 8  then trunc ((trunc (date '1970-01-01' + p_UT \/ 86400, 'Month') - date '1970-01-01') * 86400)     when 9  then trunc ((trunc (date '1970-01-01' + p_UT \/ 86400, 'year')  - date '1970-01-01') * 86400)     when 10 then 0     when 11 then 0     end; end;  create or replace function UT2DATESTR (p_UT number) return varchar2 deterministic is begin     return to_char (date '1970-01-01' + p_UT \/ 86400, 'YYYY.MM.DD HH24:MI:SS'); end; <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u0434 \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u0434\u0430\u043b\u0435\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0434\u043b\u044f Oracle, \u0434\u0430\u043b\u0435\u0435&nbsp;&mdash; \u0434\u043b\u044f MS SQL<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1&nbsp;&mdash; SIMP (\u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439)<\/h4>\n<p>  \u0412\u0435\u0441\u044c \u043d\u0430\u0431\u043e\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043d\u0430\u0431\u043e\u0440 \u0438\u0437 10 \u0441\u0442\u0440\u043e\u043a \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 1 \u0434\u043e 10. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c 10 \u0441\u0442\u0440\u043e\u043a \u0441 \u0443\u0441\u0435\u0447\u0451\u043d\u043d\u044b\u043c\u0438 \u0434\u043e \u0433\u0440\u0430\u043d\u0438\u0446 10 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432 \u0434\u0430\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0443 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0438 \u0443\u0441\u0435\u0447\u0451\u043d\u043d\u043e\u0439 \u0434\u0430\u0442\u0435 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c VIEW:<\/p>\n<pre><code class=\"sql\">create or replace view THINNING_HABR_SIMP_V as select STRIPE_ID      , STOCK_NAME      , TRUNC_UT (UT, STRIPE_ID)                             as UT      , avg (APRICE) keep (dense_rank first order by UT, ID) as AOPEN      , max (APRICE)                                         as AHIGH      , min (APRICE)                                         as ALOW      , avg (APRICE) keep (dense_rank last  order by UT, ID) as ACLOSE      , sum (AVOLUME)                                        as AVOLUME      , sum (APRICE * AVOLUME)                               as AAMOUNT      , count (*)                                            as ACOUNT from TRANSACTIONS_RAW   , (select rownum as STRIPE_ID from dual connect by level &lt;= 10) group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2&nbsp;&mdash; CALC (\u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e)<\/h4>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043c\u044b \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0434\u043e \u0443\u0440\u043e\u0432\u043d\u044f 1, \u0441 \u0443\u0440\u043e\u0432\u043d\u044f 1 \u0434\u043e \u0443\u0440\u043e\u0432\u043d\u044f 2, \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<pre><code class=\"sql\">create table QUOTES_CALC (       STRIPE_ID     number not null     , STOCK_NAME    varchar2 (128) not null     , UT            number not null     , AOPEN         number not null     , AHIGH         number not null     , ALOW          number not null     , ACLOSE        number not null     , AVOLUME       number not null     , AAMOUNT       number not null     , ACOUNT        number not null ) \/*partition by list (STRIPE_ID) (       partition P01 values (1)     , partition P02 values (2)     , partition P03 values (3)     , partition P04 values (4)     , partition P05 values (5)     , partition P06 values (6)     , partition P07 values (7)     , partition P08 values (8)     , partition P09 values (9)     , partition P10 values (10) )*\/ parallel 4 pctfree 0 nologging; <\/code><\/pre>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e STRIPE_ID, \u043d\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u043e\u0431\u044a\u0451\u043c\u0435 11\u041c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0433\u043e\u0434\u043d\u0435\u0435. \u041f\u0440\u0438 \u0431<b>\u043e<\/b>\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. \u0410 \u043c\u043e\u0436\u043d\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0440\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0432\u0430\u0432 \u0431\u043b\u043e\u043a \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443:<\/p>\n<pre><code class=\"sql\">create or replace procedure THINNING_HABR_CALC_T is begin      rollback;      execute immediate 'truncate table QUOTES_CALC';      insert --+ append     into QUOTES_CALC     select 1 as STRIPE_ID          , STOCK_NAME          , UT          , avg (APRICE) keep (dense_rank first order by ID)          , max (APRICE)          , min (APRICE)          , avg (APRICE) keep (dense_rank last  order by ID)          , sum (AVOLUME)          , sum (APRICE * AVOLUME)          , count (*)     from TRANSACTIONS_RAW a     group by STOCK_NAME, UT;      commit;      for i in 1..9     loop          insert --+ append         into QUOTES_CALC         select --+ parallel(4)                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, i + 1)              , avg (AOPEN)   keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE)  keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from QUOTES_CALC a         where STRIPE_ID = i         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, i + 1);          commit;      end loop;  end; \/ <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 VIEW:<\/p>\n<pre><code class=\"sql\">create view THINNING_HABR_CALC_V as select * from QUOTES_CALC; <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3&nbsp;&mdash; CHIN (\u043a\u0438\u0442\u0430\u0439\u0441\u043a\u0438\u0439 \u043a\u043e\u0434)<\/h4>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u0440\u0443\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u0445\u043e\u0434\u0430, \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u043a\u0430\u0437\u0435 \u043e\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 \u00ab\u041d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0439 \u0441\u0435\u0431\u044f\u00bb. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435&nbsp;&mdash; \u043e\u0442\u043a\u0430\u0437 \u043e\u0442 \u0446\u0438\u043a\u043b\u043e\u0432.<\/p>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b.<\/p>\n<p>  \u0417\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0435 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">create or replace view THINNING_HABR_CHIN_V as with   T01 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select 1             , STOCK_NAME             , UT             , avg (APRICE) keep (dense_rank first order by ID)             , max (APRICE)             , min (APRICE)             , avg (APRICE) keep (dense_rank last  order by ID)             , sum (AVOLUME)             , sum (APRICE * AVOLUME)             , count (*)        from TRANSACTIONS_RAW        group by STOCK_NAME, UT) , T02 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T01         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T03 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T02         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T04 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T03         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T05 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T04         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T06 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T05         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T07 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T06         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T08 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T07         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T09 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T08         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) , T10 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)    as (select                STRIPE_ID + 1              , STOCK_NAME              , TRUNC_UT (UT, STRIPE_ID + 1)              , avg (AOPEN)  keep (dense_rank first order by UT)              , max (AHIGH)              , min (ALOW)              , avg (ACLOSE) keep (dense_rank last  order by UT)              , sum (AVOLUME)              , sum (AAMOUNT)              , sum (ACOUNT)         from T09         group by STRIPE_ID, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)) select * from T01 union all select * from T02 union all select * from T03 union all select * from T04 union all select * from T05 union all select * from T06 union all select * from T07 union all select * from T08 union all select * from T09 union all select * from T10; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 4&nbsp;&mdash; UDAF<\/h4>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 User Defined Aggregated Function \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u043d\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 github.<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 5&nbsp;&mdash; PPTF (Pipelined and Parallel table function)<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u0432 \u043f\u0430\u043a\u0435\u0442\u0435):<\/p>\n<pre><code class=\"sql\">create or replace package THINNING_PPTF_P is      type TRANSACTION_RECORD_T is     record (STOCK_NAME varchar2(128), UT number, SEQ_NUM number, APRICE number, AVOLUME number);      type CUR_RECORD_T is ref cursor return TRANSACTION_RECORD_T;      type QUOTE_T     is record (STRIPE_ID number, STOCK_NAME varchar2(128), UT number              , AOPEN number, AHIGH number, ALOW number, ACLOSE number, AVOLUME number              , AAMOUNT number, ACOUNT number);      type QUOTE_LIST_T is table of QUOTE_T;      function F (p_cursor CUR_RECORD_T) return QUOTE_LIST_T     pipelined order p_cursor by (STOCK_NAME, UT, SEQ_NUM)     parallel_enable (partition p_cursor by hash (STOCK_NAME));  end; \/  create or replace package body THINNING_PPTF_P is  function F (p_cursor CUR_RECORD_T) return QUOTE_LIST_T pipelined order p_cursor by (STOCK_NAME, UT, SEQ_NUM) parallel_enable (partition p_cursor by hash (STOCK_NAME)) is     QuoteTail QUOTE_LIST_T := QUOTE_LIST_T() ;     rec TRANSACTION_RECORD_T;     rec_prev TRANSACTION_RECORD_T;     type ut_T is table of number index by pls_integer;     ut number; begin      QuoteTail.extend(10);      loop         fetch p_cursor into rec;         exit when p_cursor%notfound;          if rec_prev.STOCK_NAME = rec.STOCK_NAME         then             if    (rec.STOCK_NAME = rec_prev.STOCK_NAME and rec.UT &lt; rec_prev.UT)                or (rec.STOCK_NAME = rec_prev.STOCK_NAME and rec.UT = rec_prev.UT and rec.SEQ_NUM &lt; rec_prev.SEQ_NUM)             then raise_application_error (-20010, 'Rowset must be ordered, ('||rec_prev.STOCK_NAME||','||rec_prev.UT||','||rec_prev.SEQ_NUM||') &gt; ('||rec.STOCK_NAME||','||rec.UT||','||rec.SEQ_NUM||')');             end if;         end if;           if rec.STOCK_NAME &lt;&gt; rec_prev.STOCK_NAME or rec_prev.STOCK_NAME is null         then             for j in 1 .. 10             loop                 if QuoteTail(j).UT is not null                 then                     pipe row (QuoteTail(j));                     QuoteTail(j) := null;                 end if;             end loop;         end if;          for i in reverse 1..10         loop             ut := TRUNC_UT (rec.UT, i);              if QuoteTail(i).UT &lt;&gt; ut             then                 for j in 1..i                 loop                     pipe row (QuoteTail(j));                     QuoteTail(j) := null;                 end loop;             end if;              if QuoteTail(i).UT is null             then                  QuoteTail(i).STRIPE_ID := i;                  QuoteTail(i).STOCK_NAME := rec.STOCK_NAME;                  QuoteTail(i).UT := ut;                  QuoteTail(i).AOPEN := rec.APRICE;             end if;              if rec.APRICE &lt; QuoteTail(i).ALOW or QuoteTail(i).ALOW is null then QuoteTail(i).ALOW := rec.APRICE; end if;             if rec.APRICE &gt; QuoteTail(i).AHIGH or QuoteTail(i).AHIGH is null then QuoteTail(i).AHIGH := rec.APRICE; end if;             QuoteTail(i).AVOLUME := nvl (QuoteTail(i).AVOLUME, 0) + rec.AVOLUME;             QuoteTail(i).AAMOUNT := nvl (QuoteTail(i).AAMOUNT, 0) + rec.AVOLUME * rec.APRICE;             QuoteTail(i).ACOUNT := nvl (QuoteTail(i).ACOUNT, 0) + 1;             QuoteTail(i).ACLOSE := rec.APRICE;          end loop;          rec_prev := rec;     end loop;      for j in 1 .. 10     loop         if QuoteTail(j).UT is not null         then             pipe row (QuoteTail(j));         end if;     end loop;  exception     when no_data_needed then null; end;  end; \/ <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c VIEW:<\/p>\n<pre><code class=\"sql\">create or replace view THINNING_HABR_PPTF_V as select * from table (THINNING_PPTF_P.F (cursor (select STOCK_NAME, UT, ID, APRICE, AVOLUME from TRANSACTIONS_RAW))); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6&nbsp;&mdash; MODE (model clause)<\/h4>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 10 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0440\u0430\u0437\u044b <i>MODEL<\/i> clause \u0441 \u0444\u0440\u0430\u0437\u043e\u0439 <i>ITERATE<\/i>.<\/p>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0442\u043e\u0436\u0435 \u043d\u0435\u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u044b\u0439, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c. \u041d\u0430 \u043c\u043e\u0451\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 1000 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043f\u043e 8 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430 1 \u043c\u0438\u043d\u0443\u0442\u0443. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0444\u0440\u0430\u0437\u044b <i>MODEL<\/i>.<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0438 \u043a\u0430\u043a \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u043d\u0430 Oracle \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0441\u043a\u043e\u043b\u044c \u0443\u0433\u043e\u0434\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f PL\/SQL.<\/p>\n<p>  \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d \u043d\u0438\u0437\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0444\u0440\u0430\u0437\u044b <i>MODEL<\/i> \u0432 \u044d\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c \u0441\u043f\u0440\u0430\u0432\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f <i>\u043a\u0430\u0436\u0434\u043e\u0433\u043e<\/i> \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443 \u043d\u0430\u0441 6. \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043c \u043f\u0440\u044f\u043c\u0430\u044f \u044f\u0432\u043d\u0430\u044f \u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u044f, \u0431\u0435\u0437 \u0434\u0436\u043e\u043a\u0435\u0440\u043e\u0432. \u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0445 \u0435\u0441\u0442\u044c \u0441\u043b\u043e\u0432\u043e <i>any<\/i>&#038;nbsp&mdash; \u0442\u0430\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a dimension \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d <b>\u0434\u043e<\/b> \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u0440\u0430\u0437\u044b <i>MODEL<\/i>, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0439 \u0444\u0440\u0430\u0437\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u0443\u0445 \u0444\u0440\u0430\u0437 MODEL, \u043d\u043e \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437-\u0437\u0430 \u043d\u0438\u0437\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044e, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c <i>UT_OPEN<\/i> \u0438 <i>UT_CLOSE<\/i> \u0432 \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <i>avg () keep (dense_rank first\/last order by)<\/i> \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043e \u0444\u0440\u0430\u0437\u0435 <i>MODEL<\/i>. \u041d\u043e \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0449\u0451 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435.<br \/>  \u0418\u0437-\u0437\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"sql\">with -- \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439   SOURCETRANS (STRIPE_ID, STOCK_NAME, PARENT_UT, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)      as (select 1, STOCK_NAME, TRUNC_UT (UT, 2), UT               , avg (APRICE) keep (dense_rank first order by ID)               , max (APRICE)               , min (APRICE)               , avg (APRICE) keep (dense_rank last  order by ID)               , sum (AVOLUME)               , sum (AVOLUME * APRICE)               , count (*)          from TRANSACTIONS_RAW          where ID &lt;= 1000 -- \u0443\u0432\u0435\u043b\u0438\u0447\u044c\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0442\u0441\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0437\u0434\u0435\u0441\u044c          group by STOCK_NAME, UT) -- \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u044b PARENT_UT, UT \u0434\u043b\u044f 2...10 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0438 \u0440\u0430\u0441\u0447\u0451\u0442 UT_OPEN, UT_CLOSE -- \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 , REFMOD (STRIPE_ID, STOCK_NAME, PARENT_UT, UT, UT_OPEN, UT_CLOSE)     as (select b.STRIPE_ID              , a.STOCK_NAME              , TRUNC_UT (UT, b.STRIPE_ID + 1)              , TRUNC_UT (UT, b.STRIPE_ID)              , min (TRUNC_UT (UT, b.STRIPE_ID - 1))              , max (TRUNC_UT (UT, b.STRIPE_ID - 1))         from SOURCETRANS a           , (select rownum + 1 as STRIPE_ID from dual connect by level &lt;= 9) b         group by b.STRIPE_ID                , a.STOCK_NAME                , TRUNC_UT (UT, b.STRIPE_ID + 1)                , TRUNC_UT (UT, b.STRIPE_ID)) -- \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0438 \u043a\u0430\u0440\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 , MAINTAB     as (         select STRIPE_ID, STOCK_NAME, PARENT_UT, UT, AOPEN              , AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT, null, null from SOURCETRANS         union all         select STRIPE_ID, STOCK_NAME, PARENT_UT, UT, null              , null, null, null, null, null, null, UT_OPEN, UT_CLOSE from REFMOD)  select STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT from MAINTAB model return all rows -- \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0441\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u0430\u0440\u0442\u0443 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 2...10 reference RM on (select * from REFMOD) dimension by (STRIPE_ID, STOCK_NAME, UT) measures (UT_OPEN, UT_CLOSE) main MM partition by (STOCK_NAME) dimension by (STRIPE_ID, PARENT_UT, UT) measures (AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT) rules iterate (9) (   AOPEN   [iteration_number + 2, any, any]   =        AOPEN [cv (STRIPE_ID) - 1, cv (UT)          , rm.UT_OPEN [cv (STRIPE_ID), cv (STOCK_NAME), cv (UT)]] , ACLOSE  [iteration_number + 2, any, any]   =       ACLOSE [cv (STRIPE_ID) - 1, cv (UT)          , rm.UT_CLOSE[cv (STRIPE_ID), cv (STOCK_NAME), cv (UT)]] , AHIGH   [iteration_number + 2, any, any]   =    max (AHIGH)[cv (STRIPE_ID) - 1, cv (UT), any] , ALOW    [iteration_number + 2, any, any]   =    min (ALOW)[cv (STRIPE_ID) - 1, cv (UT), any] , AVOLUME [iteration_number + 2, any, any]   = sum (AVOLUME)[cv (STRIPE_ID) - 1, cv (UT), any] , AAMOUNT [iteration_number + 2, any, any]   = sum (AAMOUNT)[cv (STRIPE_ID) - 1, cv (UT), any] , ACOUNT  [iteration_number + 2, any, any]   = sum  (ACOUNT)[cv (STRIPE_ID) - 1, cv (UT), any] ) order by 1, 2, 3, 4; <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6&nbsp;&mdash; IDEA (ideal, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u043d\u0435\u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439)<\/h4>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u0431\u044b \u0441\u0430\u043c\u044b\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u043b \u0431\u044b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0440\u0430\u0432\u043d\u043e\u0435 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443.<\/p>\n<p>  \u041d\u043e \u043d\u0438 Oracle, \u043d\u0438 MS SQL \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0435. \u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u044d\u0442\u043e \u043f\u0440\u043e\u0434\u0438\u043a\u0442\u043e\u0432\u0430\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c.<\/p>\n<pre><code class=\"sql\">with   QUOTES_S1 as (select 1                                                as STRIPE_ID                      , STOCK_NAME                      , TRUNC_UT (UT, 1)                                 as UT                      , avg (APRICE) keep (dense_rank first order by ID) as AOPEN                      , max (APRICE)                                     as AHIGH                      , min (APRICE)                                     as ALOW                      , avg (APRICE) keep (dense_rank last  order by ID) as ACLOSE                      , sum (AVOLUME)                                    as AVOLUME                      , sum (APRICE * AVOLUME)                           as AAMOUNT                      , count (*)                                        as ACOUNT                 from TRANSACTIONS_RAW --                where rownum &lt;= 100                 group by STOCK_NAME, TRUNC_UT (UT, 1)) , T1 (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)      as (select 1, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT          from QUOTES_S1          union all          select STRIPE_ID + 1               , STOCK_NAME               , TRUNC_UT (UT, STRIPE_ID + 1)               , avg (AOPEN)  keep (dense_rank first order by UT)               , max (AHIGH)               , min (ALOW)               , avg (ACLOSE) keep (dense_rank last  order by UT)               , sum (AVOLUME)               , sum (AAMOUNT)               , sum (ACOUNT)          from T1          where STRIPE_ID &lt; 10          group by STRIPE_ID + 1, STOCK_NAME, TRUNC_UT (UT, STRIPE_ID + 1)          ) select * from T1 <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Oracle:<\/p>\n<p>  <i>If a subquery_factoring_clause refers to its own query_name in the subquery that defines it, then the subquery_factoring_clause is said to be recursive. A recursive subquery_factoring_clause must contain two query blocks: the first is the anchor member and the second is the recursive member. The anchor member must appear before the recursive member, and it cannot reference query_name. The anchor member can be composed of one or more query blocks combined by the set operators: UNION ALL, UNION, INTERSECT or MINUS. The recursive member must follow the anchor member and must reference query_name exactly once. You must combine the recursive member with the anchor member using the UNION ALL set operator.<\/i><\/p>\n<p>  \u041d\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0430\u0431\u0437\u0430\u0446\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<p>  <i>The recursive member cannot contain any of the following elements:<br \/>  The DISTINCT keyword or a GROUP BY clause<br \/>  An aggregate function. However, analytic functions are permitted in the select list.<\/i><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 recursive member \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b \u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043b\u044f <b>Oracle<\/b>.<\/p>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 CALC \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0435\u0451 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">exec THINNING_HABR_CALC_T<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0447\u0435\u0442\u044b\u0440\u0451\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 view:<\/p>\n<ul>\n<li>THINNING_HABR_SIMP_V (\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0439 SELECT, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u0433\u043e),<\/li>\n<li>THINNING_HABR_CALC_V (\u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b QUOTES_CALC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e),<\/li>\n<li>THINNING_HABR_CHIN_V (\u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0439 SELECT, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u0433\u043e),<\/li>\n<li>THINNING_HABR_PPTF_V (\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e THINNING_HABR_PPTF).<\/li>\n<\/ul>\n<p>  \u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0440\u0435\u043d\u044b \u043c\u043d\u043e\u0439 \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 VIEW \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">select count (*) as CNT      , sum (STRIPE_ID) as S_STRIPE_ID, sum (UT) as S_UT      , sum (AOPEN) as S_AOPEN, sum (AHIGH) as S_AHIGH, sum (ALOW) as S_ALOW      , sum (ACLOSE) as S_ACLOSE, sum (AVOLUME) as S_AVOLUME      , sum (AAMOUNT) as S_AAMOUNT, sum (ACOUNT) as S_ACOUNT from THINNING_HABR_XXXX_V <\/code><\/pre>\n<p>  \u0433\u0434\u0435 XXXX \u2014 SIMP, CHIN, PPTF.<\/p>\n<p>  \u042d\u0442\u0438 VIEW \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u043d\u0430\u0431\u043e\u0440\u0430. \u0414\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c fetch \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u043a\u0435\u0442\u0430 dbms_sqlhash, \u043d\u043e \u044d\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430, \u0434\u0430 \u0438 \u0440\u0430\u0441\u0447\u0451\u0442 \u0445\u044d\u0448\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u044b\u0441\u0442\u0440\u043e.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u0432 12c \u0435\u0441\u0442\u044c \u043f\u0430\u043a\u0435\u0442 DBMS_COMPARISON.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432. \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442\u044b \u0442\u0430\u043a\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c (\u043f\u0440\u0438 11\u041c \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e, \u043f\u043e\u0440\u044f\u0434\u043a\u0430 15 \u043c\u0438\u043d\u0443\u0442):<\/p>\n<pre><code class=\"sql\">with   T1 as (select 'SIMP' as ALG_NAME, a.* from THINNING_HABR_SIMP_V a          union all          select 'CALC', a.* from THINNING_HABR_CALC_V a          union all          select 'CHIN', a.* from THINNING_HABR_CHIN_V a          union all          select 'PPTF', a.* from THINNING_HABR_PPTF_V a) select ALG_NAME      , count (*) as CNT      , sum (STRIPE_ID) as S_STRIPE_ID, sum (UT) as S_UT      , sum (AOPEN) as S_AOPEN, sum (AHIGH) as S_AHIGH, sum (ALOW) as S_ALOW      , sum (ACLOSE) as S_ACLOSE, sum (AVOLUME) as S_AVOLUME      , sum (AAMOUNT) as S_AAMOUNT, sum (ACOUNT) as S_ACOUNT from T1 group by ALG_NAME; <\/code><\/pre>\n<p>  \u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u0441\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0432\u044b\u0434\u0430\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0451\u043c \u0432\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430 <b>MS SQL<\/b>. \u042f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 2016.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0431\u0430\u0437\u0443 DBTEST, \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  create table TRANSACTIONS_RAW (         STOCK_NAME  varchar (32)     not null       , UT          int              not null       , APRICE      numeric (22, 12) not null       , AVOLUME     numeric (22, 12) not null       , ID          bigint identity  not null ); <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u041d\u0430 MSSQL \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b format_mssql.bcp:<\/p>\n<pre><code class=\"sql\">12.0 3 1       SQLCHAR          0       0      &quot;,&quot;    3     UT                    &quot;&quot; 2       SQLCHAR          0       0      &quot;,&quot;    4     APRICE                &quot;&quot; 3       SQLCHAR          0       0      &quot;\\n&quot;   5     AVOLUME               &quot;&quot; <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442 LoadData-MSSQL.sql \u0432 SSMS (\u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0431\u044b\u043b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c powershell \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u043b\u044f Oracle).<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  create or alter function TRUNC_UT (@p_UT bigint, @p_StripeTypeId int) returns bigint as begin     return     case @p_StripeTypeId     when 1  then @p_UT     when 2  then @p_UT \/ 10 * 10     when 3  then @p_UT \/ 60 * 60     when 4  then @p_UT \/ 600 * 600     when 5  then @p_UT \/ 3600 * 3600     when 6  then @p_UT \/ 14400 * 14400     when 7  then @p_UT \/ 86400 * 86400     when 8  then datediff (second, cast ('1970-01-01 00:00:00' as datetime), dateadd(m,  datediff (m,  0, dateadd (second, @p_UT, cast ('1970-01-01 00:00:00' as datetime))), 0))     when 9  then datediff (second, cast ('1970-01-01 00:00:00' as datetime), dateadd(yy, datediff (yy, 0, dateadd (second, @p_UT, cast ('1970-01-01 00:00:00' as datetime))), 0))     when 10 then 0     when 11 then 0     end; end;  go  create or alter function UT2DATESTR (@p_UT bigint) returns datetime as begin     return dateadd(s, @p_UT, cast ('1970-01-01 00:00:00' as datetime)); end;  go <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432:<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1&nbsp;&mdash; SIMP<\/h4>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  create or alter view dbo.THINNING_HABR_SIMP_V as with   T1 (STRIPE_ID)      as (select 1          union all          select STRIPE_ID + 1 from T1 where STRIPE_ID &lt; 10) , T2 as (select STRIPE_ID               , STOCK_NAME               , dbo.TRUNC_UT (UT, STRIPE_ID)             as UT               , min (1000000 * cast (UT as bigint) + ID) as AOPEN_UT               , max (APRICE)                             as AHIGH               , min (APRICE)                             as ALOW               , max (1000000 * cast (UT as bigint) + ID) as ACLOSE_UT               , sum (AVOLUME)                            as AVOLUME               , sum (APRICE * AVOLUME)                   as AAMOUNT               , count (*)                                as ACOUNT          from TRANSACTIONS_RAW, T1          group by STRIPE_ID, STOCK_NAME, dbo.TRUNC_UT (UT, STRIPE_ID)) select t.STRIPE_ID, t.STOCK_NAME, t.UT, t_op.APRICE as AOPEN, t.AHIGH      , t.ALOW, t_cl.APRICE as ACLOSE, t.AVOLUME, t.AAMOUNT, t.ACOUNT from T2 t join TRANSACTIONS_RAW t_op on (t.STOCK_NAME = t_op.STOCK_NAME and t.AOPEN_UT  \/ 1000000 = t_op.UT and t.AOPEN_UT  % 1000000 = t_op.ID) join TRANSACTIONS_RAW t_cl on (t.STOCK_NAME = t_cl.STOCK_NAME and t.ACLOSE_UT \/ 1000000 = t_cl.UT and t.ACLOSE_UT % 1000000 = t_cl.ID); <\/code><\/pre>\n<p>  \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <i>first\/last<\/i> \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u0432\u043e\u0439\u043d\u044b\u043c \u0441\u0430\u043c\u043e\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2&nbsp;&mdash; CALC<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0438 view:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  create table dbo.QUOTES_CALC (       STRIPE_ID   int not null     , STOCK_NAME  varchar(32) not null     , UT          bigint not null     , AOPEN       numeric (22, 12) not null     , AHIGH       numeric (22, 12) not null     , ALOW        numeric (22, 12) not null     , ACLOSE      numeric (22, 12) not null     , AVOLUME     numeric (38, 12) not null     , AAMOUNT     numeric (38, 12) not null     , ACOUNT      int not null );  go  create or alter procedure dbo.THINNING_HABR_CALC as begin     set nocount on;      truncate table QUOTES_CALC;      declare @StripeId int;      with       T1 as (select STOCK_NAME                   , UT                   , min (ID)                   as AOPEN_ID                   , max (APRICE)               as AHIGH                   , min (APRICE)               as ALOW                   , max (ID)                   as ACLOSE_ID                   , sum (AVOLUME)              as AVOLUME                   , sum (APRICE * AVOLUME)     as AAMOUNT                   , count (*)                  as ACOUNT              from TRANSACTIONS_RAW              group by STOCK_NAME, UT)     insert into QUOTES_CALC (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)     select 1, t.STOCK_NAME, t.UT, t_op.APRICE, t.AHIGH, t.ALOW, t_cl.APRICE, t.AVOLUME, t.AAMOUNT, t.ACOUNT     from T1 t     join TRANSACTIONS_RAW t_op on (t.STOCK_NAME = t_op.STOCK_NAME and t.UT = t_op.UT and t.AOPEN_ID  = t_op.ID)     join TRANSACTIONS_RAW t_cl on (t.STOCK_NAME = t_cl.STOCK_NAME and t.UT = t_cl.UT and t.ACLOSE_ID = t_cl.ID);      set @StripeId = 1;      while (@StripeId &lt;= 9)     begin          with           T1 as (select STOCK_NAME                       , dbo.TRUNC_UT (UT, @StripeId + 1)    as UT                       , min (UT)                            as AOPEN_UT                       , max (AHIGH)                         as AHIGH                       , min (ALOW)                          as ALOW                       , max (UT)                            as ACLOSE_UT                       , sum (AVOLUME)                       as AVOLUME                       , sum (AAMOUNT)                       as AAMOUNT                       , sum (ACOUNT)                        as ACOUNT                  from QUOTES_CALC                  where STRIPE_ID = @StripeId                  group by STOCK_NAME, dbo.TRUNC_UT (UT, @StripeId + 1))         insert into QUOTES_CALC (STRIPE_ID, STOCK_NAME, UT, AOPEN, AHIGH, ALOW, ACLOSE, AVOLUME, AAMOUNT, ACOUNT)         select @StripeId + 1, t.STOCK_NAME, t.UT, t_op.AOPEN, t.AHIGH, t.ALOW, t_cl.ACLOSE, t.AVOLUME, t.AAMOUNT, t.ACOUNT         from T1 t         join QUOTES_CALC t_op on (t.STOCK_NAME = t_op.STOCK_NAME and t.AOPEN_UT  = t_op.UT)         join QUOTES_CALC t_cl on (t.STOCK_NAME = t_cl.STOCK_NAME and t.ACLOSE_UT = t_cl.UT)         where t_op.STRIPE_ID = @StripeId and t_cl.STRIPE_ID = @StripeId;          set @StripeId = @StripeId + 1;      end;  end;  go  create or alter view dbo.THINNING_HABR_CALC_V as select * from dbo.QUOTES_CALC;  go <\/code><\/pre>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b 3 (CHIN) \u0438 4 (UDAF) \u044f \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b \u043d\u0430 MS SQL.<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 5&nbsp;&mdash; PPTF<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 view. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e\u0439, \u0430 \u043d\u0435 parallel pipelined table function, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u0441\u0432\u043e\u0451 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u0442 Oracle:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  create or alter function dbo.THINNING_HABR_PPTF () returns @rettab table (       STRIPE_ID  bigint           not null     , STOCK_NAME varchar(32)      not null     , UT         bigint           not null     , AOPEN      numeric (22, 12) not null     , AHIGH      numeric (22, 12) not null     , ALOW       numeric (22, 12) not null     , ACLOSE     numeric (22, 12) not null     , AVOLUME    numeric (38, 12) not null     , AAMOUNT    numeric (38, 12) not null     , ACOUNT     bigint           not null) as begin      declare @i tinyint;     declare @tut int;      declare @trans_STOCK_NAME varchar(32);     declare @trans_UT int;     declare @trans_ID int;     declare @trans_APRICE numeric (22,12);     declare @trans_AVOLUME numeric (22,12);      declare @trans_prev_STOCK_NAME varchar(32);     declare @trans_prev_UT int;     declare @trans_prev_ID int;     declare @trans_prev_APRICE numeric (22,12);     declare @trans_prev_AVOLUME numeric (22,12);      declare @QuoteTail table (           STRIPE_ID  bigint           not null primary key clustered         , STOCK_NAME varchar(32)      not null         , UT         bigint           not null         , AOPEN      numeric (22, 12) not null         , AHIGH      numeric (22, 12)         , ALOW       numeric (22, 12)         , ACLOSE     numeric (22, 12)         , AVOLUME    numeric (38, 12) not null         , AAMOUNT    numeric (38, 12) not null         , ACOUNT     bigint           not null);      declare c cursor fast_forward for     select STOCK_NAME, UT, ID, APRICE, AVOLUME     from TRANSACTIONS_RAW     order by STOCK_NAME, UT, ID; -- THIS ORDERING (STOCK_NAME, UT, ID) IS MANDATORY      open c;      fetch next from c into @trans_STOCK_NAME, @trans_UT, @trans_ID, @trans_APRICE, @trans_AVOLUME;      while  @@fetch_status = 0     begin          if @trans_STOCK_NAME &lt;&gt; @trans_prev_STOCK_NAME or @trans_prev_STOCK_NAME is null         begin             insert into @rettab select * from @QuoteTail;             delete @QuoteTail;         end;          set @i = 10;         while @i &gt;= 1         begin             set @tut = dbo.TRUNC_UT (@trans_UT, @i);              if @tut &lt;&gt; (select UT from @QuoteTail where STRIPE_ID = @i)             begin                 insert into @rettab select * from @QuoteTail where STRIPE_ID &lt;= @i;                 delete @QuoteTail where STRIPE_ID &lt;= @i;             end;              if (select count (*) from @QuoteTail where STRIPE_ID = @i) = 0             begin                 insert into @QuoteTail (STRIPE_ID, STOCK_NAME, UT, AOPEN, AVOLUME, AAMOUNT, ACOUNT)                 values (@i, @trans_STOCK_NAME, @tut, @trans_APRICE, 0, 0, 0);             end;              update @QuoteTail             set AHIGH = case when AHIGH &lt; @trans_APRICE or AHIGH is null then @trans_APRICE else AHIGH end               , ALOW = case when ALOW &gt; @trans_APRICE or ALOW is null then @trans_APRICE else ALOW end               , ACLOSE = @trans_APRICE, AVOLUME = AVOLUME + @trans_AVOLUME               , AAMOUNT = AAMOUNT + @trans_APRICE * @trans_AVOLUME               , ACOUNT = ACOUNT + 1             where STRIPE_ID = @i;              set @i = @i - 1;          end;          set @trans_prev_STOCK_NAME = @trans_STOCK_NAME;         set @trans_prev_UT = @trans_UT;         set @trans_prev_ID = @trans_ID;         set @trans_prev_APRICE = @trans_APRICE;         set @trans_prev_AVOLUME = @trans_AVOLUME;          fetch next from c into @trans_STOCK_NAME, @trans_UT, @trans_ID, @trans_APRICE, @trans_AVOLUME;      end;      close c;     deallocate c;      insert into @rettab select * from @QuoteTail;      return;  end  go    create or alter view dbo.THINNING_HABR_PPTF_V as select * from dbo.THINNING_HABR_PPTF (); <\/code><\/pre>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0440\u0430\u0441\u0447\u0451\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b QUOTES_CALC \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430 CALC \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"sql\">use DBTEST  go  exec dbo.THINNING_HABR_CALC <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0442\u0440\u0451\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0442\u0440\u0451\u0445 view:<\/p>\n<ul>\n<li>THINNING_HABR_SIMP_V (\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0439 SELECT, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u0433\u043e),<\/li>\n<li>THINNING_HABR_CALC_V (\u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b QUOTES_CALC, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e)<\/li>\n<li>THINNING_HABR_PPTF_V (\u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e THINNING_HABR_PPTF).<\/li>\n<\/ul>\n<p>  \u0414\u043b\u044f \u0434\u0432\u0443\u0445 VIEW \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">select count (*) as CNT      , sum (STRIPE_ID) as S_STRIPE_ID, sum (UT) as S_UT      , sum (AOPEN) as S_AOPEN, sum (AHIGH) as S_AHIGH, sum (ALOW) as S_ALOW      , sum (ACLOSE) as S_ACLOSE, sum (AVOLUME) as S_AVOLUME      , sum (AAMOUNT) as S_AAMOUNT, sum (ACOUNT) as S_ACOUNT from THINNING_HABR_XXXX_V<\/code><\/pre>\n<p>  \u0433\u0434\u0435 XXXX&nbsp;&mdash; SIMP, PPTF.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0442\u0440\u0451\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0434\u043b\u044f MS SQL. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435:<\/p>\n<pre><code class=\"sql\">use DBTEST  go  with   T1 as (select 'SIMP' as ALG_NAME, a.* from THINNING_HABR_SIMP_V a          union all          select 'CALC', a.* from THINNING_HABR_CALC_V a          union all          select 'PPTF', a.* from THINNING_HABR_PPTF_V a) select ALG_NAME      , count (*) as CNT, sum (cast (STRIPE_ID as bigint)) as STRIPE_ID      , sum (cast (UT as bigint)) as UT, sum (AOPEN) as AOPEN      , sum (AHIGH) as AHIGH, sum (ALOW) as ALOW, sum (ACLOSE) as ACLOSE, sum (AVOLUME) as AVOLUME      , sum (AAMOUNT) as AAMOUNT, sum (cast (ACOUNT as bigint)) as ACOUNT from T1 group by ALG_NAME; <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044f\u043c&nbsp;&mdash; \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u043e \u0442\u0440\u0451\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439.<\/p>\n<p>  \u042f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 MS SQL \u043d\u0435\u0432\u044b\u0441\u043e\u043a\u0430\u044f.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0438\u0436\u043a\u043e\u043c MS SQL, \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u043e\u0431\u044a\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438: \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b:<\/p>\n<pre><code class=\"sql\">create unique clustered index TRANSACTIONS_RAW_I1 on TRANSACTIONS_RAW (STOCK_NAME, UT, ID); create unique clustered index QUOTES_CALC_I1 on QUOTES_CALC (STRIPE_ID, STOCK_NAME, UT); <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043c\u043e\u0435\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ss\/4s\/7x\/ss4s7xhwteedzj1qgsjmb20hvvw.png\"  alt=\"image\"\/><\/div>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/yaroslavbat\/thinning_habr\">github<\/a>: Oracle, \u0441\u0445\u0435\u043c\u0430 THINNING&nbsp;&mdash; \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0441\u0445\u0435\u043c\u0430 THINNING_LIVE&nbsp;&mdash; <i>\u043e\u043d\u043b\u0430\u0439\u043d-\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435<\/i> \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0430\u0439\u0442\u0430 bitcoincharts.com \u0438 <i>\u043e\u043d\u043b\u0430\u0439\u043d-\u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435<\/i> (\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u0430\u0439\u0442 \u0432 \u043e\u043d\u043b\u0430\u0439\u043d-\u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u0434\u0430\u0451\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 5 \u0434\u043d\u0435\u0439), \u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f MS SQL \u0442\u043e\u0436\u0435 \u043f\u043e \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>  <b>\u0412\u044b\u0432\u043e\u0434:<\/b><\/p>\n<p>  \u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430 Oracle, \u0447\u0435\u043c \u043d\u0430 MS SQL. \u0421 \u0440\u043e\u0441\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0440\u0430\u0437\u0440\u044b\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c.<\/p>\n<p>  \u041d\u0430 Oracle \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432\u0430\u0440\u0438\u0430\u043d\u0442 PPTF. \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432\u044b\u0433\u043e\u0434\u043d\u0435\u0435, \u0442\u0430\u043a\u043e\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0447\u0430\u0441\u0442\u043e. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438 \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442&nbsp;&mdash; \u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0434\u0430\u0436\u0435 \u043e\u0431\u044a\u0451\u043c 367\u041c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 (\u043c\u0435\u0442\u043e\u0434 PPTF \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043b \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u0430 \u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u0447\u0430\u0441\u0430).<\/p>\n<p>  \u041d\u0430 MS SQL \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0447\u0451\u0442\u0430 (CALC).<\/p>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434 PPTF \u043d\u0430 Oracle \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043b\u0438\u0434\u0435\u0440\u043e\u043c? \u0418\u0437-\u0437\u0430 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0438\u0437-\u0437\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b&nbsp;&mdash; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043a\u0430\u043a parallel pipelined table function, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u043f\u043b\u0430\u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/za\/ss\/nl\/zassnleqabvacrdkxnumjhd5mky.png\" alt=\"image\"\/><\/div>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/418757\/\"> https:\/\/habr.com\/post\/418757\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418757\/\" class=\"post__text post__text-html js-mediator-article\">\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u0438\u0440\u043e\u0432\u043e\u043a \u0440\u044b\u043d\u043a\u0430 \u0424\u043e\u0440\u0435\u043a\u0441 (\u0442\u043e\u0447\u043d\u0435\u0435, \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u043e\u0432).<\/p>\n<p>  \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438: \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0432 \u0442\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<ul>\n<li>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 (\u043a\u043e\u0434 \u043f\u0430\u0440\u044b USDEUR \u0438 \u043f\u0440.),<\/li>\n<li>\u0414\u0430\u0442\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 unix time,<\/li>\n<li>Open value (\u0446\u0435\u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0434\u0435\u043b\u043a\u0438 \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435),<\/li>\n<li>High value (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430),<\/li>\n<li>Low value (\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0435\u043d\u0430),<\/li>\n<li>Close value (\u0446\u0435\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0434\u0435\u043b\u043a\u0438),<\/li>\n<li>Volume (\u0433\u0440\u043e\u043c\u043a\u043e\u0441\u0442\u044c, \u0438\u043b\u0438 \u043e\u0431\u044a\u0451\u043c \u0441\u0434\u0435\u043b\u043a\u0438).<\/li>\n<\/ul>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442 \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: 5 \u0441\u0435\u043a, 15 \u0441\u0435\u043a, 1 \u043c\u0438\u043d, 5 \u043c\u0438\u043d, 15 \u043c\u0438\u043d, \u0438 \u0442.\u0434.<\/p>\n<p>  \u041e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 OHLC, \u0438\u043b\u0438 OHLCV (Open, High, Low, Close, Volume). \u041e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043e, \u043f\u043e \u043d\u0435\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u00ab\u042f\u043f\u043e\u043d\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438\u00bb.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/by\/ws\/8u\/byws8uaklvxydw8d2wqkqhpb1ni.png\" alt=\"image\"\/><\/div>\n<p>  \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043a\u0430\u043a\u0438\u0435 \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0440\u0435\u0436\u0438\u0432\u0430\u0442\u044c (\u0443\u043a\u0440\u0443\u043f\u043d\u044f\u0442\u044c) \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0438\u043c\u043d\u0435\u0433\u043e \u0441\u043a\u0430\u0447\u043a\u0430 \u0446\u0435\u043d\u044b \u0431\u0438\u0442\u043a\u043e\u0438\u043d\u0430, \u0430 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0432\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435 \u0433\u0440\u0430\u0444\u0438\u043a \u00ab\u042f\u043f\u043e\u043d\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438\u00bb (\u0432 MS Excel \u0442\u0430\u043a\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c). \u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0434\u043b\u044f \u0442\u0430\u0439\u043c\u0444\u0440\u0435\u0439\u043c\u0430 \u00ab1 \u043c\u0435\u0441\u044f\u0446\u00bb, \u0434\u043b\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u00abbitstampUSD\u00bb. \u0411\u0435\u043b\u043e\u0435 \u0442\u0435\u043b\u043e \u0441\u0432\u0435\u0447\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0440\u043e\u0441\u0442 \u0446\u0435\u043d\u044b \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435, \u0447\u0451\u0440\u043d\u043e\u0435&nbsp;&mdash; \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u044b, \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0438 \u043d\u0438\u0436\u043d\u0438\u0435 \u0444\u0438\u0442\u0438\u043b\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u043b\u0438\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435. \u0424\u043e\u043d&nbsp;&mdash; \u043e\u0431\u044a\u0451\u043c \u0441\u0434\u0435\u043b\u043e\u043a. \u0425\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0434\u0435\u043a\u0430\u0431\u0440\u0435 2017 \u0446\u0435\u043d\u0430 \u0432\u043f\u043b\u043e\u0442\u043d\u0443\u044e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043b\u0430\u0441\u044c \u043a \u043e\u0442\u043c\u0435\u0442\u043a\u0435 20\u041a.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0434\u0432\u0438\u0436\u043a\u043e\u0432 \u0411\u0414, \u0434\u043b\u044f Oracle \u0438 MS SQL, \u0447\u0442\u043e, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u043e\u0434\u0435, \u0434\u0430\u0441\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 (\u043e\u0431\u043e\u0431\u0449\u0430\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c).  <\/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-287855","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287855","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=287855"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287855\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}