diff --git a/53项目部署说明书/v2.4.0_sql/1hjz_视图SQL.sql b/53项目部署说明书/v2.4.0_sql/1hjz_视图SQL.sql index afe2582..45e6095 100644 --- a/53项目部署说明书/v2.4.0_sql/1hjz_视图SQL.sql +++ b/53项目部署说明书/v2.4.0_sql/1hjz_视图SQL.sql @@ -108,17 +108,20 @@ LEFT JOIN admin_info a ON f.feedback_by = a.user_id; -- 创建客户商家关系视图 CREATE VIEW rel_consumer_merchant_view AS -SELECT t3.user_id, - IF ( - t3.merchant_no = t4.coupon_merchant_no, - t3.merchant_no, +SELECT + c.user_id + ,IF ( + IFNULL(tmp1.merchant_no,'') = IFNULL(tmp2.coupon_merchant_no,''), + IFNULL(tmp1.merchant_no,''), GROUP_CONCAT( - t3.merchant_no, + IFNULL(tmp1.merchant_no,''), '&', - t4.coupon_merchant_no + IFNULL(tmp2.coupon_merchant_no,'') ) - ) merchant_no -FROM + ) merchant_no +FROM + consumer_info c +LEFT JOIN ( SELECT t1.user_id, @@ -132,54 +135,94 @@ FROM ) ) merchant_no FROM - ( - select t.user_id, GROUP_CONCAT(t.merchant_no ORDER BY t.merchant_no asc separator '&') order_merchant from ( - select DISTINCT c.user_id, v.merchant_no FROM consumer_info c, vorder v - WHERE c.user_id = v.user_id - GROUP BY c.user_id, v.merchant_no - ) t - - GROUP BY t.user_id - ) t1, - ( - select t.user_id, GROUP_CONCAT(t.merchant_no ORDER BY t.merchant_no asc separator '&') card_merchant_no FROM - ( - select DISTINCT c.user_id, s.merchant_no FROM consumer_info c, service_card s - WHERE c.user_id = s.user_id + SELECT + t.user_id, + GROUP_CONCAT( + t.merchant_no + ORDER BY + t.merchant_no ASC SEPARATOR '&' + ) order_merchant + FROM + ( + SELECT DISTINCT + c.user_id, + v.merchant_no + FROM + consumer_info c, + vorder v + WHERE + c.user_id = v.user_id + GROUP BY + c.user_id, + v.merchant_no + ) t + GROUP BY + t.user_id + ) t1, + ( + SELECT + t.user_id, + GROUP_CONCAT( + t.merchant_no + ORDER BY + t.merchant_no ASC SEPARATOR '&' + ) card_merchant_no + FROM + ( + SELECT DISTINCT + c.user_id, + s.merchant_no + FROM + consumer_info c, + service_card s + WHERE + c.user_id = s.user_id + GROUP BY + c.user_id, + s.merchant_no + ) t + GROUP BY + t.user_id + ) t2 + WHERE + t1.user_id = t2.user_id + GROUP BY + t1.user_id +) tmp1 +ON c.user_id = tmp1.user_id - GROUP BY c.user_id,s.merchant_no - ) t +LEFT JOIN - GROUP BY t.user_id - ) t2 - where t1.user_id = t2.user_id - GROUP BY t1.user_id -) t3, ( -select t.user_id, GROUP_CONCAT(t.merchant_no ORDER BY t.merchant_no asc separator '&') coupon_merchant_no FROM -( -select DISTINCT c.user_id, cp.merchant_no FROM consumer_info c, coupon cp -WHERE c.user_id = cp.user_id - -GROUP BY c.user_id,cp.merchant_no -) t - -GROUP BY t.user_id -) t4 -WHERE t3.user_id = t4.user_id -GROUP BY t3.user_id; - --- 创建服务卡与预约明细关系视图 -CREATE VIEW rel_service_card_book_detail AS SELECT - s.card_no, - s.card_name, - b.book_no -FROM - service_card s, - book_detail b -WHERE - s.card_no = b.card_no; + SELECT + t.user_id, + GROUP_CONCAT( + t.merchant_no + ORDER BY + t.merchant_no ASC SEPARATOR '&' + ) coupon_merchant_no + FROM + ( + SELECT DISTINCT + c.user_id, + cp.merchant_no + FROM + consumer_info c, + coupon cp + WHERE + c.user_id = cp.user_id + GROUP BY + c.user_id, + cp.merchant_no + ) t + GROUP BY + t.user_id +) tmp2 +ON c.user_id = tmp2.user_id +GROUP BY c.user_id + ,tmp1.merchant_no + ,tmp2.coupon_merchant_no -- SELECT * FROM CONSUMER_BASE_INFO_VIEW;