TsCustomerGenderStatisticMapper.xml 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.huiju.estateagents.statistic.mapper.TsCustomerGenderStatisticMapper">
  4. <select id="getNewCustomerSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
  5. SELECT
  6. org_id,realty_consultant,
  7. sum(if(sex = 1,1,0)) as man_sum,
  8. sum(if(sex = 1,1,0))/count(*) as man_pct,
  9. sum(if(sex = 2,1,0)) as woman_sum,
  10. sum(if(sex = 2,1,0))/count(*) as woman_pct,
  11. sum(if(sex != 1 and sex != 2,1,0)) as unknown_sum,
  12. sum(if(sex != 1 and sex != 2,1,0))/count(*) as unknown_pct
  13. FROM
  14. ta_recommend_customer
  15. WHERE
  16. date_format( create_date, '%Y-%m-%d' ) = date_format( #{nowDate}, '%Y-%m-%d' )
  17. GROUP BY org_id,realty_consultant
  18. </select>
  19. <select id="getFollowUpSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
  20. SELECT
  21. t.org_id,
  22. t.follower_id as realty_consultant,
  23. sum( IF ( t.customer_sex = 1, 1, 0 ) ) AS manSum,
  24. sum( IF ( t.customer_sex = 1, 1, 0 ) ) / count( * ) AS manPct,
  25. sum( IF ( t.customer_sex = 2, 1, 0 ) ) AS womanSum,
  26. sum( IF ( t.customer_sex = 2, 1, 0 ) ) / count( * ) AS womanPct,
  27. sum( IF ( t.customer_sex != 1 AND t.customer_sex != 2, 1, 0 ) ) AS unknownSum,
  28. sum( IF ( t.customer_sex != 1 AND t.customer_sex != 2, 1, 0 ) ) / count( * ) AS unknownPct
  29. FROM
  30. ( SELECT * FROM ta_customer_follow_up_record GROUP BY customer_id ) t
  31. GROUP BY
  32. t.org_id,t.follower_id
  33. </select>
  34. <select id="getVisiteSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
  35. SELECT
  36. d.org_id,
  37. d.realty_consultant,
  38. sum( IF ( d.sex = 1, 1, 0 ) ) AS manSum,
  39. sum( IF ( d.sex = 1, 1, 0 ) ) / count( * ) AS manPct,
  40. sum( IF ( d.sex = 2, 1, 0 ) ) AS womanSum,
  41. sum( IF ( d.sex = 2, 1, 0 ) ) / count( * ) AS womanPct,
  42. sum( IF ( d.sex != 1 AND d.sex != 2, 1, 0 ) ) AS unknownSum,
  43. sum( IF ( d.sex != 1 AND d.sex != 2, 1, 0 ) ) / count( * ) AS unknownPct
  44. FROM
  45. (
  46. SELECT
  47. t.enlist_id,
  48. c.*
  49. FROM
  50. ta_activity_dynamic_enlist t
  51. LEFT JOIN ta_recommend_customer c ON t.person_id = c.person_id
  52. AND t.building_id = c.building_id
  53. AND t.org_id = c.org_id
  54. WHERE
  55. t.is_checkin = 1
  56. GROUP BY
  57. c.customer_id
  58. ) d
  59. GROUP BY
  60. d.org_id,d.realty_consultant
  61. </select>
  62. </mapper>