تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2332 أدوات العرض

I want to calculate the opportunity / lead conversion rate. I have the following code:  My problem is in the form of pivot field percent, which is not calculated as properly as on pgadmin. . someone help me, i'm very thanks

def _select(self):
select_str = super(OpportunityReport, self)._select()
select_str
+= """,
c.x_mien AS x_mien,
c.group_id AS group_id,
c.brand_id AS brand_id,
c.x_trangthai_lead AS x_trangthai_lead,
c.x_phanloai_lead AS x_phanloai_lead,
c.customer_care AS customer_care,
count(c.type) as lead,
sum(CASE WHEN c.type = 'opportunity' THEN 1 ELSE 0 END) AS opportunity,
(100 * sum(CASE WHEN c.type = 'opportunity' THEN 1 ELSE 0 END))/count(*) as percent
"""
return select_str

def _group_by(self):
group_by_str = super(OpportunityReport, self)._group_by()
group_by_str
+= """,
c.x_mien,
c.group_id,
c.brand_id,
c.x_trangthai_lead,
c.x_phanloai_lead,
c.customer_care
"""
return group_by_str

d
الصورة الرمزية
إهمال
الكاتب

Chào,

Ibrahim

Tôi đã thử mã của bạn, vấn đề là các trường "phần trăm" vẫn nhận được giá trị trường "cơ hội".

Mã của tôi chạy ở pgadmin là "phần trăm" = (cơ hội / khách hàng tiềm năng). Nhưng đi đến trục vẫn đang lấy giá trị theo oppo.

أفضل إجابة

Hi,
You need to provide us more info about the difference between the results of Pgadmin and the pivot view. 
In addition to that, which table your alias c refers to ? 

I would suggest this note to try at first : 

(sum(CASE WHEN c.type = 'opportunity' THEN 1 ELSE 0 END)::Float*100/count(distinct c.id)) as percent

Waiting to hear from you.
Thumps up if this helps.
Regards.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 24
29
2
أغسطس 23
2087
1
نوفمبر 22
5610
1
أكتوبر 21
3287
0
مارس 20
1844