我试图找到这个查询的底部。
我真的很难过。 我使用我的联接错了,我无法弄清楚,也许我的结构也是错误的。
我需要从naedo
表格中获取更多记录。
account_details
是主(父)表,还包含数据所在的类别(在网格下面为蓝色= mfin和绿色= emprica)
paysoft_results
包含所有付款信息('成功',不成功,跟踪,争议)
我只对“成功'
NAEDO表包含应该发生的付款(DISTINCT负责的奇数双重条目除外)
现在我没有从NAEDO那里获得足够的回报,而且球队的领先表示我在正确的赛道上,但我是否理解加入?所以我认为可能存在问题所在。
select
ad.EMPIRICA,
ad.MFIN,
sum(n.cnt) as NAEDO,
sum(ps.cnt) as paySoft,
round(sum(ps.cnt) / sum(n.cnt) * 100,1) as percent
from
(
select
account_no,
to_char(trunc(empirica_score - 5, -1) + 5, '9999') || '-' || to_char(trunc(empirica_score - 5, -1) + 14, '9999') as EMPIRICA,
to_char(trunc((mfin_score - 1) / 25) * 25 + 1, 'fm000') || '-' || to_char(trunc((mfin_score - 1) / 25) * 25 + 25, 'fm000') as MFIN
from account_details
) ad
left join
(
select custno, count(*) as cnt
from paysoft_results
where result = 'Successful'
and resultdate >= cast(date_trunc('month', (current_date- interval '1 month')) as date)+12
and resultdate <= cast(date_trunc('month', current_date) as date) + 11
group by custno
) ps on ps.custno = ad.account_no
right outer join
(
select customer_code, count(distinct start_date) as cnt
from naedo
where start_date >= cast(date_trunc('month', (current_date- interval '1 month')) as date)+12
and start_date <= cast(date_trunc('month', current_date) as date) + 11
group by customer_code
) n on n.customer_code = ad.account_no
group by ad.EMPIRICA, ad.MFIN
order by ad.EMPIRICA, ad.MFIN;
以前的问题与某些额外相关的信息
关系
数据将在网格上显示。与
[account_detail]empirica_score
作为行标题
和
[account_detail]mfin_score
作为列标题
account_details
第一个子选择。只是为了catagories。
查询需要获取epirica_score
和mfin_score
来确定网格上的展示位置(例如99%的位置)
获取密钥匹配的distinct
的{{1}}值
或多或少像这样
[NAEDO]startdate
我不知道如何处理这样的查询。它是一份碧玉报道。
任何想法?
这里有一些(希望)有用的数据
account_details表
account_no title surname firstname empirica_score mfin_score 1000002222 "Mr" "Petersen" "Andrew peter" 602 97 1000002828 "Mr" "Mars" "Abraham" 599 97
NAEDO TBALE
customer_code name start_date 1000002828 "Abraham Mars" "2014-08-01" 1000002828 "Abraham Mars" "2014-09-03" 1000002828 "Abraham Mars" "2014-08-01" 1000002828 "Abraham Mars" "2014-07-03" 1000002222 "Andrew peter Petersen" "2014-05-23" 1000002222 "Andrew peter Petersen" "2014-08-22" 1000002222 "Andrew peter Petersen" "2014-07-23" 1000002222 "Andrew peter Petersen" "2014-07-23" 1000002222 "Andrew peter Petersen" "2014-06-23"
paysoft_results表
custno name result result_date 1000002828 "Abraham Mars" "Successful" "2014-07-05" 1000002828 "Abraham Mars" "Tracking" "2014-08-01" 1000002828 "Abraham Mars" "Successful" "2014-08-01" 1000002828 "Abraham Mars" "Tracking" "2014-09-03" 1000002828 "Abraham Mars" "Successful" "2014-09-06" 1000002222 "Andrew peter Petersen" "Successful" "2014-08-25" 1000002222 "Andrew peter Petersen" "Successful" "2014-06-25" 1000002222 "Andrew peter Petersen" "Tracking" "2014-08-22" 1000002222 "Andrew peter Petersen" "Successful" "2014-05-23" 1000002222 "Andrew peter Petersen" "Successful" "2014-07-25" 1000002222 "Andrew peter Petersen" "Tracking" "2014-07-23"
亚伯拉罕有3次付款和3次NAEDO记录(start_date DISTINCT)
即3/3 * 100 = 100%
他已经在网格上代表(虽然它的99%)
安德鲁有4笔付款和4封NAEDO记录(start_date DISTINCT)
即4/4 * 100 = 100%
他应该在网格上的同一个地方。
也许在后台我可以收集所有网格位置分数并点按百分比计算。
一个客户的代表