{"id":1653,"date":"2021-11-02T12:58:29","date_gmt":"2021-11-02T03:58:29","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=1653"},"modified":"2021-11-06T12:47:25","modified_gmt":"2021-11-06T03:47:25","slug":"sql-server-to-extract-daily_sales-and-7day_avg","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2021\/11\/02\/sql-server-to-extract-daily_sales-and-7day_avg\/","title":{"rendered":"T-SQL \u3067\u65e5\u5225\u53d7\u6ce8\u30687\u65e5\u79fb\u52d5\u5e73\u5747\u3092\u62bd\u51fa"},"content":{"rendered":"<p>&nbsp;<br \/>\nMS SQL Server \u3092\u4f7f\u3046\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e <a href=\"https:\/\/github.com\/Microsoft\/sql-server-samples\/releases\/tag\/wide-world-importers-v1.0\" rel=\"noopener\" target=\"_blank\">WideWorldImportersDW<\/a> \u30b9\u30ad\u30fc\u30de\u3092\u4f7f\u3063\u3066 T-SQL \u3092\u899a\u3048\u308b\u3002<\/p>\n<p>Fact.Sale \u304b\u3089\u65e5\u5225\u53d7\u6ce8\u91d1\u984d\u30687\u65e5\u9593\u79fb\u52d5\u5e73\u5747\u3092\u62bd\u51fa\u3059\u308b\u30af\u30a8\u30ea<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT\r\n    &#x5B;Invoice Date Key] as sale_date,\r\n    sum(&#x5B;Total Including Tax]) as total_sale,\r\n    avg(sum(&#x5B;Total Including Tax])) over(\r\n        order by\r\n            &#x5B;Invoice Date Key] rows between 6 preceding and current row\r\n    ) as avg_seven_days\r\nFROM\r\n    &#x5B;WideWorldImportersDW].&#x5B;Fact].&#x5B;Sale]\r\nwhere\r\n    &#x5B;Invoice Date Key] between '2013-01-01' and '2013-01-31'\r\ngroup by\r\n    &#x5B;Invoice Date Key]\r\norder by\r\n    &#x5B;Invoice Date Key];\r\n<\/pre>\n<p>&nbsp;<br \/>\n\u7d50\u679c\u306f\u3053\u3046\u306a\u308b\u3002<\/p>\n<div id=\"attachment_1659\" style=\"width: 311px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1659\" src=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/tsql-2021-11-02.png\" alt=\"query results\" width=\"301\" height=\"334\" class=\"size-full wp-image-1659\" srcset=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/tsql-2021-11-02.png 301w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/tsql-2021-11-02-270x300.png 270w\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" \/><p id=\"caption-attachment-1659\" class=\"wp-caption-text\">\u65e5\u5225\u53d7\u6ce8\u30687\u65e5\u79fb\u52d5\u5e73\u5747<\/p><\/div>\n<p>&nbsp;<br \/>\nPowerBI \u3067\u8868\u793a\u3059\u308b\u3068\u3053\u3046\u306a\u308b\u3002<\/p>\n<div id=\"attachment_1660\" style=\"width: 1025px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1660\" src=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/pbi-2021-11-02.png\" alt=\"power bi\" width=\"1015\" height=\"500\" class=\"size-full wp-image-1660\" srcset=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/pbi-2021-11-02.png 1015w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/pbi-2021-11-02-300x148.png 300w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/pbi-2021-11-02-768x378.png 768w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2021\/11\/pbi-2021-11-02-624x307.png 624w\" sizes=\"auto, (max-width: 1015px) 100vw, 1015px\" \/><p id=\"caption-attachment-1660\" class=\"wp-caption-text\">PowerBI \u3067\u8868\u793a<\/p><\/div>\n<p>&nbsp;<\/p>\n<h3>\u53c2\u8003\u56f3\u66f8<\/h3>\n<p><a href=\"https:\/\/amzn.to\/3bLFEpv\" rel=\"noopener\" target=\"_blank\">\u30d3\u30c3\u30b0\u30c7\u30fc\u30bf\u5206\u6790\u30fb\u6d3b\u7528\u306e\u305f\u3081\u306eSQL\u30ec\u30b7\u30d4<\/a><br \/>\n<a href=\"https:\/\/amzn.to\/3nX2FLU\" rel=\"noopener\" target=\"_blank\">SQL Server 2016\u306e\u6559\u79d1\u66f8 \u958b\u767a\u7de8<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; MS SQL Server \u3092\u4f7f\u3046\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002 \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e WideWorldImportersDW \u30b9\u30ad\u30fc\u30de\u3092\u4f7f\u3063\u3066 T-SQL \u3092\u899a\u3048\u308b\u3002 Fact.Sale \u304b\u3089\u65e5\u5225\u53d7\u6ce8\u91d1\u984d\u30687\u65e5\u9593\u79fb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,20,23],"tags":[],"class_list":["post-1653","post","type-post","status-publish","format-standard","hentry","category-azure","category-sql","category-t-sql"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=1653"}],"version-history":[{"count":8,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1653\/revisions"}],"predecessor-version":[{"id":1683,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1653\/revisions\/1683"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}