Fix product performance grouped JSON build
This commit is contained in:
@@ -3230,7 +3230,8 @@ func queryProductPerformanceSQLGroupRows(ctx context.Context, pg *sql.DB, mode,
|
||||
return nil, err
|
||||
}
|
||||
query := productPerformanceSQLSourceCTE(mode) + fmt.Sprintf(`
|
||||
SELECT jsonb_build_object(
|
||||
SELECT (
|
||||
jsonb_build_object(
|
||||
'group_value', group_value,
|
||||
'label', group_value,
|
||||
'count', row_count,
|
||||
@@ -3247,7 +3248,9 @@ SELECT jsonb_build_object(
|
||||
'urun_ilk_grubu', CASE WHEN $%d = 'urun_ilk_grubu' THEN group_value ELSE urun_ilk_grubu END,
|
||||
'urun_ana_grubu', CASE WHEN $%d = 'urun_ana_grubu' THEN group_value ELSE urun_ana_grubu END,
|
||||
'urun_alt_grubu', CASE WHEN $%d = 'urun_alt_grubu' THEN group_value ELSE urun_alt_grubu END,
|
||||
'market_key', CASE WHEN $%d = 'market_key' THEN group_value ELSE market_key END,
|
||||
'market_key', CASE WHEN $%d = 'market_key' THEN group_value ELSE market_key END
|
||||
)
|
||||
|| jsonb_build_object(
|
||||
'stock_qty', stock_qty,
|
||||
'sales_qty_90d', sales_qty_90d,
|
||||
'sales_qty_180d', sales_qty_180d,
|
||||
@@ -3265,7 +3268,9 @@ SELECT jsonb_build_object(
|
||||
'gross_profit_usd_90d', gross_profit_usd_90d,
|
||||
'gross_profit_usd_180d', gross_profit_usd_180d,
|
||||
'gross_margin_90d', gross_margin_90d,
|
||||
'gross_margin_180d', gross_margin_180d,
|
||||
'gross_margin_180d', gross_margin_180d
|
||||
)
|
||||
|| jsonb_build_object(
|
||||
'unit_profit_cost_90d', unit_profit_cost_90d,
|
||||
'unit_profit_cost_180d', unit_profit_cost_180d,
|
||||
'unit_profit_base_90d', unit_profit_base_90d,
|
||||
@@ -3286,6 +3291,7 @@ SELECT jsonb_build_object(
|
||||
'stock_turnover_180d', CASE WHEN avg_stock_180d > 0 THEN sales_qty_180d / NULLIF(avg_stock_180d,0) ELSE 0 END,
|
||||
'stock_turnover_365d', CASE WHEN avg_stock_365d > 0 THEN sales_qty_365d / NULLIF(avg_stock_365d,0) ELSE 0 END,
|
||||
'stock_turnover_total', CASE WHEN avg_stock_total > 0 THEN sales_qty_total / NULLIF(avg_stock_total,0) ELSE 0 END
|
||||
)
|
||||
) AS row_json
|
||||
FROM (
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user