pgsql记录一次统计查询

SELECT "ehi"."houses_id"                                         AS 楼盘id,
       "ehi"."houses_name"                                       AS 项目名称,
       "ehi"."developer"                                         AS 开发商,
       Concat_ws('--', "ehi"."min_acreage", "ehi"."max_acreage") AS 面积,
       CASE
         WHEN "ehi"."property" = 'house'THEN '住宅'
         WHEN "ehi"."property" = 'business' THEN '商业'
         WHEN "ehi"."property" = 'villa' THEN '别墅'
         WHEN "ehi"."property" = 'offices' THEN '写字楼'
         WHEN "ehi"."property" = 'shop' THEN '商铺'
         WHEN "ehi"."property" = 'apartment' THEN '公寓'
         WHEN "ehi"."property" = 'synthesize' THEN '综合楼'
         WHEN "ehi"."property" = 'enterprise' THEN '企业独栋'
         WHEN "ehi"."property" = 'affordable' THEN '经济适用房'
         WHEN "ehi"."property" = 'foreign-style-house' THEN '洋房'
         WHEN "ehi"."property" = 'two-limit-house' THEN '两限房'
         WHEN "ehi"."property" = 'commodity-house' THEN '自住型商品房'
         ELSE '未知'
       END                                                       AS 物业类型,
       CASE
         WHEN "ehi"."source" = 0 THEN '后台'
         WHEN "ehi"."source" = 1 THEN '后台'
         WHEN "ehi"."source" = 2 THEN '经纪人'
         ELSE '未知'
       END                                                       AS 创建方式,
       CASE
        
         WHEN "ehi"."is_show" = 1
              AND "ehi"."check_state" = 1 THEN '上架中'
       END                                                       AS 状态,
       "ebi"."broker_name"                                       AS 超级管理人员,
       "ebi"."broker_mobile"                                     AS 超级管理人员手机号,
       "ehc".counselor_count                                     AS 顾问总数,
       "edc".type_count                                          AS 户型总数,
       "ea"."name"                                               AS 所在省,
       "eb"."name"                                               AS 所在市,
       "ec"."name"                                               AS 所在区,
       To_timestamp("ehi"."create_time")                         AS 发布时间,
       "ehi"."houses_address"                                    AS 详细地址,
       CASE
         WHEN "return_type" = 1 THEN '固定'
                                     || "return_percentage"
                                     || '%'
         WHEN "return_type" = 0 THEN return_price
                                     || '-'
                                     || return_max_price
       END                                                       AS 佣金,
       CASE
         WHEN "houses_unit" = '万元/套' THEN houses_min_price
                                                || '-'
                                                || houses_max_price
                                                || '万元/套'
         WHEN "houses_unit" = '万元' THEN houses_min_price
                                            || '-'
                                            || houses_max_price
                                            || '万元'
         WHEN "houses_unit" = '元/平米' THEN houses_min_price
                                                || '-'
                                                || houses_max_price
                                                || '元/平米'
         WHEN "houses_unit" = '元' THEN houses_min_price
                                         || '-'
                                         || houses_max_price
                                         || '元'
       END                                                       AS 售价,
       "ehi"."return_rule"                                       AS 佣金规则
FROM   ex_houses_info ehi
       LEFT JOIN ex_broker_info ebi
              ON ehi.uid = ebi.broker_uid
       LEFT JOIN (SELECT "house_id",
                         Count(*) AS counselor_count
                  FROM   "ex_houses_counselor"
                  WHERE  "is_freeze" = 0
                  GROUP  BY "house_id") AS "ehc"
              ON "ehi"."houses_id" = "ehc"."house_id"
       LEFT JOIN (SELECT "house_id",
                         Count(*) AS type_count
                  FROM   "ex_house_type"
                  GROUP  BY "house_id") AS "edc"
              ON "ehi"."houses_id" = "edc"."house_id"
       LEFT JOIN ex_area ea
              ON ehi.house_province = ea.id
       LEFT JOIN ex_area eb
              ON ehi.houses_city = eb.id
       LEFT JOIN ex_area ec
              ON ehi.houses_location = ec.id

你可能感兴趣的:(Mysql)