fix(sf-21b): _INLINE_VELOCITY_SQL weighted AVG (P0 follow-up) #291
1 changed files with 10 additions and 3 deletions
|
|
@ -118,9 +118,16 @@ _INLINE_VELOCITY_SQL = text("""
|
|||
ELSE crm.room_bucket
|
||||
END AS room_bucket,
|
||||
SUM(crm.deals_total_count) AS deals_window,
|
||||
AVG(crm.deals_total_avg_area_m2) AS avg_area_m2,
|
||||
AVG(crm.deals_total_avg_price_thousand_rub_per_m2)
|
||||
* 1000.0 AS avg_price_per_m2_rub,
|
||||
COALESCE(
|
||||
SUM(crm.deals_total_avg_area_m2 * crm.deals_total_count)
|
||||
/ NULLIF(SUM(crm.deals_total_count), 0),
|
||||
0
|
||||
)::numeric(10, 2) AS avg_area_m2,
|
||||
COALESCE(
|
||||
SUM(crm.deals_total_avg_price_thousand_rub_per_m2 * crm.deals_total_count)
|
||||
/ NULLIF(SUM(crm.deals_total_count), 0),
|
||||
0
|
||||
)::numeric(12, 2) * 1000.0 AS avg_price_per_m2_rub,
|
||||
array_agg(DISTINCT cm.domrf_obj_id) AS competitor_obj_ids,
|
||||
COUNT(DISTINCT cm.domrf_obj_id) AS competitor_count,
|
||||
MIN(crm.report_month) AS window_start,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue