Advertisement
Pandaaaa906

产品成交信息

Aug 20th, 2024
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2. prd.id,
  3. prd.cat_no 货号,
  4. prd.cas,
  5. coalesce(so_summary.近一年成交次数::float / NULLIF(GREATEST(inq_summary.近一年询价次数, so_summary.近一年成交次数), 0), 0) 近一年成交率,
  6. inq_summary.*,
  7. so_summary.*,
  8. coalesce(rd32_summary.近一年毛利率, 0) 近一年毛利率
  9.  
  10. FROM t_product prd
  11.  
  12. -- 询价汇总 inq_summary
  13.     INNER JOIN LATERAL (
  14.         SELECT
  15.         COUNT(distinct inq_d.inq_order_id) FILTER(WHERE inq_m.create_time >= now() - INTERVAL '12 month') 近一年询价次数
  16.  
  17.         FROM "public".t_inq_order_detail_offer inq_quo
  18.        
  19.         INNER JOIN "public".t_inq_order_detail inq_d
  20.         ON inq_quo.id = inq_d.id
  21.        
  22.         INNER JOIN "public".t_inq_order inq_m
  23.         ON inq_d.inq_order_id = inq_m.id
  24.    
  25.         WHERE 1=1
  26.         AND inq_quo.is_delete = 1
  27.         AND inq_quo.brand_no = prd.cat_no
  28. --      AND inq_quo.create_time >= now() - INTERVAL '1 month'
  29.        
  30. --      GROUP BY inq_quo.brand_no
  31.     ) inq_summary
  32.     ON TRUE
  33.    
  34.     -- 销售订单汇总
  35.     INNER JOIN LATERAL (
  36.         SELECT
  37.         count(distinct so_d."ID") filter(WHERE so_m."dDate" >= now() - interval '12 month') 近一年成交次数
  38.         FROM u8_009."SO_SODetails" so_d
  39.  
  40.         INNER JOIN u8_009."SO_SOMain" so_m
  41.         ON so_d."ID" = so_m."ID"
  42.        
  43.         LEFT JOIN "public".t_inq_sync_crm_detail crm_so
  44.         ON crm_so.sal_order_detail_id = so_d."iSOsID"::text
  45.        
  46.         WHERE so_m.dverifysystime is not NULL
  47.         AND (so_d."cSCloser" is null or so_d."cSCloser" = 'asuser')
  48.         AND so_d."cInvCode" = prd.cat_no
  49.     ) so_summary
  50.     ON TRUE
  51.  
  52. LEFT JOIN (
  53.     SELECT
  54.     rd32_d."cInvCode",
  55.     avg(((so_d."iSum" - coalesce(crm_so_d.loss_amount, 0)) / so_d."iQuantity" * rd32_d."iQuantity" - rd32_d."iPrice") / nullif(((so_d."iSum" - coalesce(crm_so_d.loss_amount, 0)) / so_d."iQuantity" * rd32_d."iQuantity"), 0)) 近一年毛利率
  56.     FROM u8_009.rdrecord32 rd32_m
  57.    
  58.     LEFT JOIN u8_009.rdrecords32 rd32_d
  59.     ON rd32_d."ID" = rd32_m."ID"
  60.    
  61.     LEFT JOIN u8_009."SO_SODetails" so_d
  62.     ON so_d."iSOsID" = rd32_d.iorderdid
  63.    
  64.     LEFT JOIN "public".t_inq_sync_crm_detail crm_so_d
  65.     ON crm_so_d.sal_order_detail_id = so_d."iSOsID"::text
  66.     AND crm_so_d.is_delete = 1
  67.    
  68.     LEFT JOIN u8_009."Inventory" inv
  69.     ON inv."cInvCode"= rd32_d."cInvCode"
  70.    
  71.     WHERE 1=1
  72. --  AND rd32_m."cCusCode" = cus.code
  73.     AND rd32_m."dDate" >= now() - '1 year'::interval
  74.     AND rd32_m.dnverifytime is not null
  75.     AND rd32_d."iPrice" is not null
  76.     AND rd32_d."iQuantity" > 0
  77.     AND inv."cInvCCode" in (
  78. --  '03011006',
  79.     '03021005'  -- 药物线
  80. --  '03031001',
  81. --  '03051001'
  82.     )
  83.     GROUP BY rd32_d."cInvCode"
  84. ) rd32_summary
  85. ON rd32_summary."cInvCode" = prd.cat_no
  86.  
  87. WHERE 1=1
  88. AND prd.is_delete = 1
  89. AND prd.brand_name = 'cato'
  90. AND prd.cat_no = 'C4X-201663'   -- 改这里
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement