{"id":3413,"date":"2024-06-13T08:30:44","date_gmt":"2024-06-12T23:30:44","guid":{"rendered":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/?p=3413"},"modified":"2024-09-27T17:23:24","modified_gmt":"2024-09-27T08:23:24","slug":"054","status":"publish","type":"post","link":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/blog\/articles\/bigquery\/054\/","title":{"rendered":"\u3010BigQuery\u3011SQL\u3067\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u3082\u3064\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u306f\u3058\u3081\u306b<\/h2>\n\n\n\n<p>\u793e\u5185\u696d\u52d9\u306e\u4e2d\u3067\u3001\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u3082\u3064\u30c7\u30fc\u30bf\u30de\u30fc\u30c8\u3092\u4f5c\u6210\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u9867\u5ba2\u30e9\u30f3\u30af\u306f\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u306e\u4e2d\u3067\u3082\u91cd\u8981\u306a\u6307\u6a19\u306e\u3072\u3068\u3064\u306b\u306a\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3001\u53c2\u8003\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL\u3067\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u6301\u3064\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u4eca\u56de\u306fArray\u3092\u7528\u3044\u3066\u8cfc\u8cb7\u306e\u306a\u3044\u6708\u306e\u6b20\u640d\u30c7\u30fc\u30bf\u3092\u88dc\u3044\u3064\u3064\u3001\u5404\u6708\u306e\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u7b97\u51fa\u3059\u308b\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-mainblue-color\">\u9867\u5ba2\u30e9\u30f3\u30af\u306e\u5b9a\u7fa9\u306b\u3064\u3044\u3066<\/mark><\/h3>\n\n\n\n<p>\u4eca\u56de\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5b9a\u7fa9\u3067\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<br>\u30af\u30a8\u30ea\u3092\u53c2\u8003\u306b\u3059\u308b\u5834\u5408\u306f\u3001\u6700\u5f8c\u306e\u30e9\u30f3\u30af\u5224\u5b9a\u6642\u306b\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30e9\u30f3\u30af\u6761\u4ef6\u3092\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><strong>\u25bc\u9867\u5ba2\u30e9\u30f3\u30af<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table p-table-side-heading\"><table><tbody><tr><th>\u8cfc\u5165\u7dcf\u56de\u6570\/\u8cfc\u5165\u7dcf\u91d1\u984d<\/th><th class=\"has-text-align-center\" data-align=\"center\">4,500\u5186\u672a\u6e80<\/th><th class=\"has-text-align-center\" data-align=\"center\">4,500\u5186\u4ee5\u4e0a~19,800\u5186\u672a\u6e80<\/th><th class=\"has-text-align-center\" data-align=\"center\">19,800\u5186\u4ee5\u4e0a<\/th><\/tr><tr><th>2\u56de\u4ee5\u4e0a<\/th><td class=\"has-text-align-center\" data-align=\"center\">E<\/td><td class=\"has-text-align-center\" data-align=\"center\">C<\/td><td class=\"has-text-align-center\" data-align=\"center\">A<\/td><\/tr><tr><th>1\u56de<\/th><td class=\"has-text-align-center\" data-align=\"center\">F<\/td><td class=\"has-text-align-center\" data-align=\"center\">D<\/td><td class=\"has-text-align-center\" data-align=\"center\">B<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group p-block-beginner\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p><strong>\u9867\u5ba2\u30e9\u30f3\u30af\u3068\u306f<\/strong><\/p>\n\n\n\n<p>\u9867\u5ba2\u30e9\u30f3\u30af\u3068\u306f\u3001\u9867\u5ba2\u3092\u8cfc\u8cb7\u884c\u52d5\u3084\u5b9f\u7e3e\u306b\u5fdc\u3058\u3066\u30e9\u30f3\u30af\u4ed8\u3051\uff08\u91cd\u307f\u4ed8\u3051\uff09\u3092\u3059\u308b\u3053\u3068\u3092\u3044\u3044\u307e\u3059\u3002<br>\u4eca\u56de\u306f\u3001\u8cfc\u5165\u56de\u6570\uff08Frequency\uff09\u3068\u8cfc\u5165\u91d1\u984d\uff08Monetary\uff09\u3067\u30e9\u30f3\u30af\u4ed8\u3051\u3092\u3057\u3066\u30bb\u30b0\u30e1\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u6301\u3064\u30c6\u30fc\u30d6\u30eb<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-mainblue-color\">\u306e\u4f5c\u6210\u30af\u30a8\u30ea\uff08\u5168\u4f53\uff09<\/mark><\/h3>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n\/*\u6ce8\u6587\u65e5\u306eMIN\u5024\u304b\u3089MAX\u5024\u307e\u3067\u306e\u5e74\u6708\u4e00\u89a7\u3092\u4f5c\u6210*\/\nDECLARE date_array ARRAY&lt;DATE&gt;;\nSET date_array = GENERATE_DATE_ARRAY(\n      (SELECT DATE(FORMAT_DATE('%Y-%m', MIN(order_date)) || '-01') \n        FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`)\n      ,(SELECT DATE(FORMAT_DATE('%Y-%m', MAX(order_date)) || '-01') \n         FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`)\n      ,INTERVAL 1 MONTH\n  );\n\n  \/* customer_id\u3054\u3068\u306e\u6700\u521d\u306e\u6ce8\u6587\u6708\u3092\u62bd\u51fa *\/\nWITH _user AS(\n    SELECT\n      customer_id\n      ,DATE(FORMAT_DATE('%Y-%m', MIN(order_date)) || '-01') as min_order_date01 ---------- \u6700\u521d\u306e\u6ce8\u6587\u6708\u3092yyyy-mm-01\u306e\u5f62\u306b\u5909\u63db\n    FROM  `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`\n    GROUP BY customer_id\n  )\n\n  \/* customer_id\u3054\u3068\u306b\u6700\u521d\u306e\u6ce8\u6587\u6708\u4ee5\u964d\u306e\u5e74\u6708\u3092\u4ed8\u4e0e *\/\n  ,_user_dt AS(\n    SELECT \n      _user.customer_id\n      ,car.dt\n    FROM (SELECT dt from UNNEST(date_array) as dt) AS car\n    INNER JOIN _user\n      ON _user.min_order_date01 &lt;= car.dt\n  )\n\n  \/* \u9867\u5ba2\u306e\u3054\u3068\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf *\/\n  ,_trn AS(\n    SELECT \n      tran_t.customer_id\n      ,DATE(FORMAT_DATE('%Y-%m', tran_t.order_date) || '-01') AS ord_month --------------- \u6ce8\u6587\u6708\u3092yyyy-mm-01\u306e\u5f62\u306b\u5909\u63db\n      ,tran_t.order_id\n      ,tran_d_t.price\n    FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb` AS tran_t\n    LEFT JOIN `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u8a73\u7d30\u30c6\u30fc\u30d6\u30eb` AS tran_d_t\n      ON tran_t.order_id = tran_d_t.order_id\n  )\n\n  \/* \u9867\u5ba2\u306e\u3054\u3068\u306edt\u304b\u3089\u904e\u53bb1\u5e74\u5206\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf *\/\n  ,month_grouped_trn AS(\n    SELECT \n      _user_dt.customer_id\n      ,user_dt.dt\n      ,_trn.ord_month\n      ,COUNT(DISTINCT _trn.order_id) AS ord_cnt ---------------------- \u8cfc\u5165\u56de\u6570\n      ,IFNULL(SUM(_trn.price), 0) AS price\n    FROM _user_dt \n    LEFT JOIN _trn\n      ON _user_dt.customer_id = _trn.customer_id\n        AND (_trn.ord_month BETWEEN DATE_SUB(user_dt.dt, INTERVAL 11 MONTH) AND _user_dt.dt) -------- dt\u304b\u3089\u904e\u53bb1\u5e74\u5206\u306e\u30c7\u30fc\u30bf\u3092\u7d10\u3065\u3051\u308b\n    GROUP BY \n      _user_dt.customer_id\n      ,user_dt.dt\n      ,_trn.ord_month\n  )\n\n  ,_proceeds_by_customer AS(\n    SELECT\n      customer_id\n      ,dt\n      ,SUM(ord_cnt) AS ord_cnt_sum\n      ,SUM(price) AS price_sum\n    FROM month_grouped_trn\n    GROUP BY \n      customer_id\n      ,dt\n  )\n\n  -- ,customer_rank_t AS(\n    SELECT \n      customer_id\n      ,dt\n      ,ord_cnt_sum AS ord_cnt\n      ,price_sum AS price\n      ,CASE \n        WHEN ord_cnt_sum &gt;= 2 AND price_sum &gt;= 19800 THEN 'A'\n        WHEN ord_cnt_sum = 1 AND price_sum &gt;= 19800 THEN 'B'\n        WHEN ord_cnt_sum &gt;= 2 AND (price_sum BETWEEN 4500 AND 19799) THEN 'C'\n        WHEN ord_cnt_sum = 1 AND (price_sum BETWEEN 4500 AND 19799) THEN 'D'\n        WHEN ord_cnt_sum &gt;= 2 AND price_sum &lt; 4500 THEN 'E'\n        WHEN ord_cnt_sum = 1 AND price_sum &lt; 4500 THEN 'F'\n      ELSE '\u4f11\u7720' END AS customer_rank\n    FROM _proceeds_by_customer\n    ORDER BY customer_id, dt\n\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-mainblue-color\">\u30af\u30a8\u30ea\u3092\u3072\u3068\u3064\u305a\u3064\u89e3\u8aac<\/mark><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6ce8\u6587\u65e5\u306eMIN\u5024\u304b\u3089MAX\u5024\u307e\u3067\u306e\u5e74\u6708\u4e00\u89a7\u3092\u4f5c\u6210<\/strong><br><span style=\"color: initial;\">DECLARE\u95a2\u6570\u3067\u5e74\u6708\u4e00\u89a7\u306e\u30de\u30b9\u30bf\u30c7\u30fc\u30bf\u3092date_array\u3068\u3044\u3046\u540d\u524d\u3067\u5b9a\u7fa9\u3057\u307e\u3059<\/span>\u3002<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDECLARE date_array ARRAY&lt;DATE&gt;;\nSET date_array = GENERATE_DATE_ARRAY(\n      (SELECT DATE(FORMAT_DATE('%Y-%m', MIN(order_date)) || '-01')  ---- \u5e74\u6708\u4e00\u89a7\u306e\u958b\u59cb\u6708\uff1a\u6ce8\u6587\u65e5\u306eMIN\u5024\u306e\u5e74\u6708\uff08yyyy-mm-01\u306e\u5f62\uff09\n        FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`)\n      ,(SELECT DATE(FORMAT_DATE('%Y-%m', MAX(order_date)) || '-01') ---- \u5e74\u6708\u4e00\u89a7\u306e\u7d42\u4e86\u6708\uff1a\u6ce8\u6587\u65e5\u306eMAX\u5024\u306e\u5e74\u6708\uff08yyyy-mm-01\u306e\u5f62\uff09\n         FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`)\n      ,INTERVAL 1 MONTH\n  )\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9867\u5ba2\u3054\u3068\u306b\u6700\u521d\u306e\u6ce8\u6587\u6708\u4ee5\u964d\u306e\u5e74\u6708\u3092\u3082\u305f\u305b\u308b<\/strong><br><span style=\"color: initial;\">GENERATE_DATE_ARRAY\u306f\u30cd\u30b9\u30c8\u3055\u308c\u305f\u72b6\u614b\u3067\u65e5\u4ed8\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u3001UNNEST\u51e6\u7406\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002\u3053\u306e\u51e6\u7406\u3067\u3001\u305d\u306e\u9867\u5ba2\u306e\u6ce8\u6587\u304c\u306a\u3044\u5e74\u6708\u306e\u30ec\u30b3\u30fc\u30c9\u3082\u6301\u3066\u3066\u3044\u308b\u72b6\u614b\u304c\u4f5c\u6210\u3067\u304d\u307e\u3057\u305f\u3002<\/span><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n  \/* customer_id\u3054\u3068\u306e\u6700\u521d\u306e\u6ce8\u6587\u6708\u3092\u62bd\u51fa *\/\nWITH _user AS(\n    SELECT\n      customer_id\n      ,DATE(FORMAT_DATE('%Y-%m', MIN(order_date)) || '-01') as min_order_date01 ---- \u9867\u5ba2\u306e\u6700\u521d\u306e\u6ce8\u6587\u6708\u3092yyyy-mm-01\u306e\u5f62\u306b\u5909\u63db\n    FROM  `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb`\n    GROUP BY customer_id\n  )\n\n  \/* customer_id\u3054\u3068\u306b\u6700\u521d\u306e\u6ce8\u6587\u6708\u4ee5\u964d\u306e\u5e74\u6708\u3092\u4ed8\u4e0e *\/\n  ,user_dt AS(\n    SELECT \n      _user.customer_id\n      ,car.dt\n    FROM (SELECT dt from UNNEST(date_array) as dt) AS car\n    INNER JOIN _user\n      ON _user.min_order_date01 &lt;= car.dt ---- \u9867\u5ba2\u306e\u6700\u521d\u306e\u6ce8\u6587\u6708\u4ee5\u964d\u306e\u30c7\u30fc\u30bf\u304c\u7d10\u3065\u304f\u3088\u3046\u306b\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\n  )\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u904e\u53bb\u4e00\u5e74\u5206\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u7d10\u3065\u3051\u308b<\/strong><br>\u57fa\u6e96\u3068\u306a\u308b\u5e74\u6708\uff08dt\uff09\u306b\u5bfe\u3057\u3066\u3001\u904e\u53bb1\u5e74\u9593\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u6301\u305f\u305b\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5404\u9867\u5ba2\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u3092\u904e\u53bb1\u5e74\u9593\u306e\u307f\u306b\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u3067\u30e9\u30f3\u30af\u3092\u6b63\u3057\u304f\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n  \/* \u9867\u5ba2\u306e\u3054\u3068\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf *\/\n  ,_trn AS(\n    SELECT \n      tran_t.customer_id\n      ,DATE(FORMAT_DATE('%Y-%m', tran_t.order_date) || '-01') AS ord_month --------------- \u6ce8\u6587\u6708\u3092yyyy-mm-01\u306e\u5f62\u306b\u5909\u63db\n      ,tran_t.order_id\n      ,tran_d_t.price\n    FROM `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf\u30c6\u30fc\u30d6\u30eb` AS tran_t\n    LEFT JOIN `\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u8a73\u7d30\u30c6\u30fc\u30d6\u30eb` AS tran_d_t\n      ON tran_t.order_id = tran_d_t.order_id\n  )\n\n  \/* \u9867\u5ba2\u306e\u3054\u3068\u306edt\u304b\u3089\u904e\u53bb1\u5e74\u5206\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30c7\u30fc\u30bf *\/\n  ,month_grouped_trn AS(\n    SELECT \n      _user_dt.customer_id\n      ,user_dt.dt\n      ,_trn.ord_month\n      ,COUNT(DISTINCT _trn.order_id) AS ord_cnt ---------------------- \u8cfc\u5165\u56de\u6570\n      ,IFNULL(SUM(_trn.price), 0) AS price ---------------- \u8cfc\u5165\u91d1\u984d\uff1aNULL\u306e\u30ec\u30b3\u30fc\u30c9\u306f\uff10\u5186\u3068\u3059\u308b\n    FROM _user_dt \n    LEFT JOIN _trn\n      ON _user_dt.customer_id = _trn.customer_id\n        AND (_trn.ord_month BETWEEN DATE_SUB(user_dt.dt, INTERVAL 11 MONTH) AND _user_dt.dt) -------- dt\u304b\u3089\u904e\u53bb1\u5e74\u5206\u306e\u30c7\u30fc\u30bf\u3092\u7d10\u3065\u3051\u308b\n    GROUP BY \n      _user_dt.customer_id\n      ,user_dt.dt\n      ,_trn.ord_month\n  )\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9867\u5ba2\u30fb\u5e74\u6708\u3054\u3068\u306b\u8cfc\u5165\u56de\u6570\u30fb\u8cfc\u5165\u91d1\u984d\u3092\u96c6\u8a08\u3057\u3001\u305d\u306e\u7d50\u679c\u306b\u3088\u3063\u3066\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u4ed8\u4e0e\u3059\u308b<\/strong><br>\u30e9\u30f3\u30af\u3092\u4ed8\u4e0e\u3067\u304d\u306a\u3044\uff08=1\u5e74\u4ee5\u4e0a\u8cfc\u5165\u304c\u306a\u3044\uff09\u9867\u5ba2\u3092<strong>\u4f11\u7720\u9867\u5ba2<\/strong>\u3068\u5b9a\u7fa9\u3057\u307e\u3059<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n,_proceeds_by_customer AS(\n    SELECT\n      customer_id\n      ,dt\n      ,SUM(ord_cnt) AS ord_cnt_sum\n      ,SUM(price) AS price_sum\n    FROM month_grouped_trn\n    GROUP BY \n      customer_id\n      ,dt\n  )\n\n  -- ,_customer_rank_t AS(\n    SELECT \n      customer_id\n      ,dt\n      ,ord_cnt_sum AS ord_cnt\n      ,price_sum AS price\n      ,CASE \n        WHEN ord_cnt_sum &gt;= 2 AND price_sum &gt;= 19800 THEN 'A'\n        WHEN ord_cnt_sum = 1 AND price_sum &gt;= 19800 THEN 'B'\n        WHEN ord_cnt_sum &gt;= 2 AND (price_sum BETWEEN 4500 AND 19799) THEN 'C'\n        WHEN ord_cnt_sum = 1 AND (price_sum BETWEEN 4500 AND 19799) THEN 'D'\n        WHEN ord_cnt_sum &gt;= 2 AND price_sum &lt; 4500 THEN 'E'\n        WHEN ord_cnt_sum = 1 AND price_sum &lt; 4500 THEN 'F'\n      ELSE '\u4f11\u7720' END AS customer_rank\n    FROM _proceeds_by_customer\n    ORDER BY customer_id, dt\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u304a\u308f\u308a\u306b<\/h2>\n\n\n\n<p>\u9867\u5ba2\u30e9\u30f3\u30af\u306f\u8cfc\u8cb7\u72b6\u6cc1\u306b\u3088\u3063\u3066\u5909\u52d5\u3059\u308b\u306e\u3067\u3001\u4e00\u822c\u7684\u306aUU\u6570\u306e\u30ab\u30a6\u30f3\u30c8\u306a\u3069\u3088\u308a\u3082\u8907\u96d1\u306a\u51e6\u7406\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3088\u308a\u5b9f\u8df5\u7684\u306a\u30af\u30a8\u30ea\u306e\u66f8\u304d\u65b9\u304c\u5fc5\u8981\u306a\u969b\u306f\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c7\u30fc\u30bf\u6d3b\u7528\u3067\u304a\u56f0\u308a\u306e\u65b9\u306f\u3053\u3061\u3089<\/h2>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-mainblue-color\">\u30c7\u30fc\u30bf\u6d3b\u7528\u3067\u304a\u56f0\u308a\u306e\u65b9\u3078<\/mark><\/h3>\n\n\n\n<p>\u79c1\u305f\u3061DX-Accelerator\u4e8b\u696d\u3067\u306f\u3001\u30c7\u30fc\u30bf\u6d3b\u7528\u306b\u3064\u3044\u3066\u306e\u69d8\u3005\u306a\u30b9\u30ad\u30eb\u3092\u6301\u3063\u305f\u4eba\u6750\u304c\u5e38\u99d0\u3067\u30c7\u30fc\u30bf\u6d3b\u7528\u652f\u63f4\u3092\u884c\u3046\u30b5\u30fc\u30d3\u30b9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u5f53\u4e8b\u696d\u306f\u30ed\u30fc\u30f3\u30c1\u304b\u3089\u7d043\u5e74\uff0824\u5e749\u6708\u6642\u70b9\uff09\u3067\u3059\u304c\u3001\u3053\u308c\u307e\u3067\u306b\u69d8\u3005\u306a\u696d\u754c\u30fb\u696d\u7a2e\u306e\u304a\u5ba2\u3055\u307e\u306e\u304a\u624b\u4f1d\u3044\u3092\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5c11\u3057\u3067\u3082\u8208\u5473\u3092\u6301\u3063\u3066\u304f\u3060\u3055\u3063\u305f\u308a\u3001\u3059\u3067\u306b\u3054\u76f8\u8ac7\u3092\u3057\u305f\u3044\u3053\u3068\u304c\u3042\u308b\u65b9\u306f\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002\u73fe\u5728\u3042\u306a\u305f\u306e\u7d44\u7e54\u306e\u30d5\u30a7\u30fc\u30ba\u304c\u3069\u3053\u306b\u3042\u308b\u304b\u306f\u95a2\u4fc2\u3042\u308a\u307e\u305b\u3093\u3002\u307e\u305a\u306f\u304a\u8a71\u3092\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-50\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/#contact\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>\u3054\u76f8\u8ac7\u306f\u3053\u3061\u3089<\/strong><\/a><\/div>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3082\u3046\u5c11\u3057\u30b5\u30fc\u30d3\u30b9\u306b\u3064\u3044\u3066\u77e5\u308a\u305f\u3044\u65b9\u306f\u30b5\u30fc\u30d3\u30b9\u7d39\u4ecb\u8cc7\u6599\u3082\u3054\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-50\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/lp.uncovertruth.co.jp\/dxa\/wp000?_ga=2.2578416.1516286710.1708917420-1991674602.1708917420\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>\u30b5\u30fc\u30d3\u30b9\u7d39\u4ecb\u8cc7\u6599<\/strong><\/a><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group p-entry-author\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-columns p-entry-author-header is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column p-author-pict is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1108\" height=\"1108\" src=\"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited.jpg\" alt=\"\" class=\"wp-image-3648\" srcset=\"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited.jpg 1108w, https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited-300x300.jpg 300w, https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited-1024x1024.jpg 1024w, https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited-150x150.jpg 150w, https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited-768x768.jpg 768w, https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp\/wp-content\/uploads\/2024\/06\/IMG_3661-edited-120x120.jpg 120w\" sizes=\"auto, (max-width: 1108px) 100vw, 1108px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column p-author-name is-layout-flow wp-block-column-is-layout-flow\">\n<p>\u3053\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u4eba<\/p>\n\n\n\n<p class=\"c-author-name\"><strong>\u5bae\u5d0e \u745b\u68a8<\/strong><br><strong>\uff08\u307f\u3084\u3056\u304d \u3048\u308a\uff09<\/strong><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"p-author-profile\"><strong>\u682a\u5f0f\u4f1a\u793eUNCOVER TRUTH<br>\u30d3\u30b8\u30cd\u30b9\u30c7\u30d9\u30ed\u30c3\u30d7\u30e1\u30f3\u30c8\u30b0\u30eb\u30fc\u30d7 DX-Accelerator\u30c1\u30fc\u30e0<\/strong><br>\u98df\u54c1\u88fd\u9020\u4f1a\u793e\u306e\u54c1\u8cea\u7ba1\u7406\u8077\u3092\u7d4c\u3066\u30012023\u5e74\u306bUNCOVER TRUTH\u306b\u4e2d\u9014\u5165\u793e\u3002<br>\u5e83\u544a\u4ee3\u7406\u5e97\u3084\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u652f\u63f4\u4f1a\u793e\u3067\u30c7\u30fc\u30bf\u6d3b\u7528\u696d\u52d9\u3092\u652f\u63f4\u3002<br>\u3088\u304f\u4f7f\u3046\u30c4\u30fc\u30eb\u306fBigQuery\u3001Denodo\u3002<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u793e\u5185\u696d\u52d9\u306e\u4e2d\u3067\u3001\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u3082\u3064\u30c7\u30fc\u30bf\u30de\u30fc\u30c8\u3092\u4f5c\u6210\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u9867\u5ba2\u30e9\u30f3\u30af\u306f\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u306e\u4e2d\u3067\u3082\u91cd\u8981\u306a\u6307\u6a19\u306e\u3072\u3068\u3064\u306b\u306a\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3001\u53c2\u8003\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002 SQL\u3067\u6708\u3054\u3068\u306b\u9867\u5ba2\u30e9\u30f3\u30af\u3092\u6301 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":3499,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18],"tags":[],"blog_category":[79],"class_list":["post-3413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bigquery","blog_category-techblog"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/posts\/3413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/comments?post=3413"}],"version-history":[{"count":20,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/posts\/3413\/revisions"}],"predecessor-version":[{"id":3734,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/posts\/3413\/revisions\/3734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/media\/3499"}],"wp:attachment":[{"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/media?parent=3413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/categories?post=3413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/tags?post=3413"},{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.uncovertruth.co.jp\/dx-accelerator\/wp-json\/wp\/v2\/blog_category?post=3413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}