{"id":444254,"date":"2025-01-08T03:02:38","date_gmt":"2025-01-08T03:02:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=444254"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=444254","title":{"rendered":"<span>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 SQL \u0434\u043b\u044f PostgreSQL \u0438\u0437 DAX \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 AI<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f DAX, \u0438 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 DAX, \u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0441 Power BI \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 DAX \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0437 Power BI. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DAX \u0431\u0435\u0437 Power BI.<\/p>\n<p>\u0422\u0435\u043c, \u043a\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u00ab\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c\u00bb DAX \u043d\u0430 PostgreSQL\u00a0\u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442 \ud83d\ude42<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043e\u0439 \u0432\u0441\u0435\u0445 DAX \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c <code>SUMMARIZECOLUMNS<\/code>. \u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 UI \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0438 DAX \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0440\u0430\u043c, \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0443\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 DAX.<\/p>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <code>SUMMARIZECOLUMNS<\/code> \u0437\u0430\u043f\u0440\u043e\u0441\u0430 DAX \u043d\u0430 SQL \u0434\u043b\u044f PostgreSQL \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AI.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0430\u0441\u0442\u044c <a href=\"https:\/\/dax.do\/PHJIwd1dc4Sxzt\/AolAgAP\/diagram\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 dax.do \u0441\u0445\u0435\u043c\u044b<\/a> \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0444\u0430\u043a\u0442\u043e\u0432 <code>Sales<\/code> \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 <code>Customer<\/code>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2dc\/c22\/31b\/2dcc2231bb495ce98eb88ba7cdd8b61c.png\" width=\"730\" height=\"361\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2dc\/c22\/31b\/2dcc2231bb495ce98eb88ba7cdd8b61c.png\"\/><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <a href=\"https:\/\/dax.do\/PHJIwd1dc4Sxzt\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u043f\u0440\u043e\u0441 DAX<\/a> \u0431\u0435\u0437 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043c\u044b\u0441\u043b\u0430, \u043b\u0438\u0448\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 DAX.<\/p>\n<pre><code class=\"sql\">EVALUATE SUMMARIZECOLUMNS (     Customer[Cars Owned],     FILTER ( Sales, Sales[Quantity] &gt; AVERAGE ( Sales[Quantity] ) ),     FILTER ( Customer, Customer[Cars Owned] &gt; 1 ),     \"Calculated Quantity\",         CALCULATE (             SUMX ( Sales, Sales[Quantity] * RELATED ( Customer[Cars Owned] ) ),             REMOVEFILTERS ( Sales[Quantity] ),             FILTER ( Customer, Customer[Cars Owned] &lt; 4 )         ) )<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0432 \u0441\u0430\u043c\u043e\u043c <code>SUMMARIZECOLUMNS<\/code> \u0447\u0435\u0440\u0435\u0437 \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c <code>FILTER ( Sales, Sales[Quantity] &gt; AVERAGE ( Sales[Quantity] ) )<\/code> \u0438 <code>FILTER ( Customer, Customer[Cars Owned] &gt; 1 )<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 UI \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u0438\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>\"Calculated Quantity\"<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 <code>CALCULATE<\/code> \u0441 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>SUMX<\/code> \u0438 <code>RELATED<\/code>, \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c <code>FILTER<\/code> \u0438 <code>REMOVEFILTERS<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>CALCULATE<\/code>.<\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439, \u0442.\u043a., \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>CALCULATE<\/code> \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u0430\u0441\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u00a0\u2014 \u0444\u0438\u043b\u044c\u0442\u0440 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <code>SUMMARIZECOLUMNS<\/code>, \u0441\u0431\u0440\u043e\u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 <code>REMOVEFILTERS ( Sales[Quantity] )<\/code> \u0438 \u00ab\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0438\u044f\u043d\u0438\u0435\u00bb \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 <code>Customer[Cars Owned] &gt; 1 &amp;&amp; Customer[Cars Owned] &lt; 4<\/code>.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c PostgreSQL \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>sales<\/code> \u0438 <code>customer<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430, \u043f\u0440\u0438\u0447\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0438, \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0442.\u0435. \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u00ab\u0441\u044b\u0440\u0430\u044f\u00bb \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438 \u0432\u0441\u044f \u0441\u0445\u0435\u043c\u0430.<\/p>\n<pre><code class=\"sql\">CREATE TABLE customer (    CustomerKey    INTEGER,    \"Cars Owned\"   INTEGER ); CREATE TABLE sales (    \"Order Number\" INTEGER,    CustomerKey    INTEGER,    Quantity       INTEGER );<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>sales<\/code> 50 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u043e \u043e\u043a\u043e\u043b\u043e 40 \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<pre><code class=\"sql\">INSERT INTO sales(\"Order Number\", CustomerKey, Quantity) SELECT number + 100000000 AS \"Order Number\",        number % 20        AS CustomerKey,        number % 10        AS Quantity FROM generate_series(1, 50000000) AS number;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>customer<\/code> 20 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"sql\">INSERT INTO customer(CustomerKey, \"Cars Owned\") SELECT number % 20        AS CustomerKey,        number % 5         AS Quantity FROM generate_series(0, 19) AS number;<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a AI, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/866534\/\" rel=\"noopener noreferrer nofollow\">\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u044c\u0448\u0435<\/a>, \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c DAX \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 PostgreSQL \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b AI \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c VIEW \u0441 \u0434\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>sales<\/code>:<\/p>\n<pre><code class=\"sql\">CREATE VIEW sales_denormilized AS SELECT s.\"Order Number\",        s.CustomerKey,        s.Quantity,        c.\"Cars Owned\" FROM sales s          INNER JOIN customer c ON s.CustomerKey = c.CustomerKey;<\/code><\/pre>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c DAX \u0434\u043b\u044f AI \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c <code>Customer[Cars Owned]<\/code> \u043d\u0430 <code>Sales[Cars Owned]<\/code>. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 AI \u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL \u0434\u043b\u044f PostgreSQL:<\/p>\n<pre><code class=\"sql\">SELECT \"Cars Owned\",        SUM(\"Calculated Quantity\") AS \"Calculated Quantity\" FROM (          SELECT \"Cars Owned\",                 (Quantity * \"Cars Owned\") AS \"Calculated Quantity\"          FROM sales_denormilized          WHERE Quantity &gt; (SELECT AVG(Quantity) FROM sales_denormilized)            AND \"Cars Owned\" &gt; 1            AND \"Cars Owned\" &lt; 4      ) subquery GROUP BY \"Cars Owned\"<\/code><\/pre>\n<p>\u0412 SQL \u043e\u0442 AI \u0432\u0438\u0434\u0435\u043d \u043b\u0438\u0448\u043d\u0438\u0439 <code>subquery<\/code>, \u043d\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u043c, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Sales[Quantity]<\/code>, \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e <code>\"Cars Owned\"<\/code>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442 AI \u043d\u0435\u0438\u0434\u0435\u0430\u043b\u0435\u043d, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0437\u0430 11 \u0441\u0435\u043a\u0443\u043d\u0434 (\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 6 \u0441\u0435\u043a\u0443\u043d\u0434, \u0435\u0441\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>sales_denormilized<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443).<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/59b\/a15\/8b6\/59ba158b6c280150fe474bb2857ac5dc.png\" width=\"561\" height=\"93\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/59b\/a15\/8b6\/59ba158b6c280150fe474bb2857ac5dc.png\"\/><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 DAX \u0432 PostgreSQL \u0431\u044b\u043b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 DAX \u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AI \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f SQL \u0434\u043b\u044f PostgreSQL, \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 DAX.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0431\u0435\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0441\u044b\u0440\u043e\u043c \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e SQL \u0434\u043b\u044f PostgreSQL \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 DAX \u0438 AI \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0430 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0441 \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0434\u0435\u043b\u043e \u0441 DAX. \u0423\u0441\u043f\u0435\u0445\u043e\u0432 \u0432 Business Intelligence \u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0430\u0445 \ud83d\ude42<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/871932\/\"> https:\/\/habr.com\/ru\/articles\/871932\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f DAX, \u0438 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 DAX, \u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0441 Power BI \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 DAX \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0437 Power BI. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DAX \u0431\u0435\u0437 Power BI.<\/p>\n<p>\u0422\u0435\u043c, \u043a\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u00ab\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c\u00bb DAX \u043d\u0430 PostgreSQL\u00a0\u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442 \ud83d\ude42<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043e\u0439 \u0432\u0441\u0435\u0445 DAX \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c <code>SUMMARIZECOLUMNS<\/code>. \u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 UI \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 \u0438 DAX \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0440\u0430\u043c, \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0443\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 DAX.<\/p>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <code>SUMMARIZECOLUMNS<\/code> \u0437\u0430\u043f\u0440\u043e\u0441\u0430 DAX \u043d\u0430 SQL \u0434\u043b\u044f PostgreSQL \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AI.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0430\u0441\u0442\u044c <a href=\"https:\/\/dax.do\/PHJIwd1dc4Sxzt\/AolAgAP\/diagram\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 dax.do \u0441\u0445\u0435\u043c\u044b<\/a> \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0444\u0430\u043a\u0442\u043e\u0432 <code>Sales<\/code> \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 <code>Customer<\/code>.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <a href=\"https:\/\/dax.do\/PHJIwd1dc4Sxzt\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u043f\u0440\u043e\u0441 DAX<\/a> \u0431\u0435\u0437 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043c\u044b\u0441\u043b\u0430, \u043b\u0438\u0448\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 DAX.<\/p>\n<pre><code class=\"sql\">EVALUATE SUMMARIZECOLUMNS (     Customer[Cars Owned],     FILTER ( Sales, Sales[Quantity] &gt; AVERAGE ( Sales[Quantity] ) ),     FILTER ( Customer, Customer[Cars Owned] &gt; 1 ),     \"Calculated Quantity\",         CALCULATE (             SUMX ( Sales, Sales[Quantity] * RELATED ( Customer[Cars Owned] ) ),             REMOVEFILTERS ( Sales[Quantity] ),             FILTER ( Customer, Customer[Cars Owned] &lt; 4 )         ) )<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0432 \u0441\u0430\u043c\u043e\u043c <code>SUMMARIZECOLUMNS<\/code> \u0447\u0435\u0440\u0435\u0437 \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c <code>FILTER ( Sales, Sales[Quantity] &gt; AVERAGE ( Sales[Quantity] ) )<\/code> \u0438 <code>FILTER ( Customer, Customer[Cars Owned] &gt; 1 )<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 UI \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u0438\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>\"Calculated Quantity\"<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 <code>CALCULATE<\/code> \u0441 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>SUMX<\/code> \u0438 <code>RELATED<\/code>, \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c <code>FILTER<\/code> \u0438 <code>REMOVEFILTERS<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>CALCULATE<\/code>.<\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439, \u0442.\u043a., \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>CALCULATE<\/code> \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u0430\u0441\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u00a0\u2014 \u0444\u0438\u043b\u044c\u0442\u0440 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <code>SUMMARIZECOLUMNS<\/code>, \u0441\u0431\u0440\u043e\u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 <code>REMOVEFILTERS ( Sales[Quantity] )<\/code> \u0438 \u00ab\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0438\u044f\u043d\u0438\u0435\u00bb \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 <code>Customer[Cars Owned] &gt; 1 &amp;&amp; Customer[Cars Owned] &lt; 4<\/code>.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c PostgreSQL \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>sales<\/code> \u0438 <code>customer<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430, \u043f\u0440\u0438\u0447\u0435\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0438, \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0442.\u0435. \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u00ab\u0441\u044b\u0440\u0430\u044f\u00bb \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438 \u0432\u0441\u044f \u0441\u0445\u0435\u043c\u0430.<\/p>\n<pre><code class=\"sql\">CREATE TABLE customer (    CustomerKey    INTEGER,    \"Cars Owned\"   INTEGER ); CREATE TABLE sales (    \"Order Number\" INTEGER,    CustomerKey    INTEGER,    Quantity       INTEGER );<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>sales<\/code> 50 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u043e \u043e\u043a\u043e\u043b\u043e 40 \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<pre><code class=\"sql\">INSERT INTO sales(\"Order Number\", CustomerKey, Quantity) SELECT number + 100000000 AS \"Order Number\",        number % 20        AS CustomerKey,        number % 10        AS Quantity FROM generate_series(1, 50000000) AS number;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>customer<\/code> 20 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"sql\">INSERT INTO customer(CustomerKey, \"Cars Owned\") SELECT number % 20        AS CustomerKey,        number % 5         AS Quantity FROM generate_series(0, 19) AS number;<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a AI, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/866534\/\" rel=\"noopener noreferrer nofollow\">\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u044c\u0448\u0435<\/a>, \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c DAX \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 PostgreSQL \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b AI \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c VIEW \u0441 \u0434\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <code>sales<\/code>:<\/p>\n<pre><code class=\"sql\">CREATE VIEW sales_denormilized AS SELECT s.\"Order Number\",        s.CustomerKey,        s.Quantity,        c.\"Cars Owned\" FROM sales s          INNER JOIN customer c ON s.CustomerKey = c.CustomerKey;<\/code><\/pre>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c DAX \u0434\u043b\u044f AI \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c <code>Customer[Cars Owned]<\/code> \u043d\u0430 <code>Sales[Cars Owned]<\/code>. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 AI \u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL \u0434\u043b\u044f PostgreSQL:<\/p>\n<pre><code class=\"sql\">SELECT \"Cars Owned\",        SUM(\"Calculated Quantity\") AS \"Calculated Quantity\" FROM (          SELECT \"Cars Owned\",                 (Quantity * \"Cars Owned\") AS \"Calculated Quantity\"          FROM sales_denormilized          WHERE Quantity &gt; (SELECT AVG(Quantity) FROM sales_denormilized)            AND \"Cars Owned\" &gt; 1            AND \"Cars Owned\" &lt; 4      ) subquery GROUP BY \"Cars Owned\"<\/code><\/pre>\n<p>\u0412 SQL \u043e\u0442 AI \u0432\u0438\u0434\u0435\u043d \u043b\u0438\u0448\u043d\u0438\u0439 <code>subquery<\/code>, \u043d\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u043c, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Sales[Quantity]<\/code>, \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e <code>\"Cars Owned\"<\/code>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442 AI \u043d\u0435\u0438\u0434\u0435\u0430\u043b\u0435\u043d, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0437\u0430 11 \u0441\u0435\u043a\u0443\u043d\u0434 (\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 6 \u0441\u0435\u043a\u0443\u043d\u0434, \u0435\u0441\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>sales_denormilized<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443).<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 DAX \u0432 PostgreSQL \u0431\u044b\u043b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 DAX \u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AI \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f SQL \u0434\u043b\u044f PostgreSQL, \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 DAX.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0431\u0435\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0441\u044b\u0440\u043e\u043c \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e SQL \u0434\u043b\u044f PostgreSQL \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 DAX \u0438 AI \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u0430 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0441 \u0434\u0435\u0441\u044f\u0442\u043a\u0430\u043c\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0432 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0434\u0435\u043b\u043e \u0441 DAX. \u0423\u0441\u043f\u0435\u0445\u043e\u0432 \u0432 Business Intelligence \u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0430\u0445 \ud83d\ude42<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/871932\/\"> https:\/\/habr.com\/ru\/articles\/871932\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-444254","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/444254","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=444254"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/444254\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}