gpt4 book ai didi

sql - 令人惊讶的困惑(不可能的)查询

转载 作者:行者123 更新时间:2023-11-29 13:30:06 26 4
gpt4 key购买 nike

我有一个问题,我不知道它是否可行。

我有 3 个表。一张父表和两个 child

enter image description here

数据将显示在网格上。与
[account_detail]empirica_score 作为行标题和
[account_detail]mfin_score 作为列标题

像这样(一秒就能飞99%)
enter image description here

因此查询需要获取 epirica_scoremfin_score 以确定在网格上的位置(例如,99% 的位置)

并获取 [NAEDO]startdate 键匹配的 distinct 值。
大致是这样的

SELECT * 
FROM paysoft_result
WHERE result_date >= "2014-08-01" and <= "2014-09-01"
AND ( SELECT COUNT( custno ) from Paysoft_result where result = 'successful' )
AND (.. some join to get the scores from account_detail .. )
AND (.. some join to get to NAEDO.. WHERE DISTINCT(start_date))

我对JOINS一无所知

  1. 因此您将获得 2 个分数来确定排名。
  2. 数量 (paysoft_result/NAEDO) * 100 = 网格值
  3. 需要按客户计算。并将总计放入网格中。

我不知道如何处理这样的查询。这是一份碧 Jade 报告。

有什么想法吗?

这里有一些(希望)有用的数据

account_details 表

account_no    title    surname    firstname    empirica_score    mfin_score   1000002222    "Mr"    "Petersen"    "Andrew peter"    602    971000002828    "Mr"    "Mars"    "Abraham"    599    97

NAEDO TBALE

customer_code    name                        start_date1000002828       "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_date1000002828     "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 记录(开始日期不同)
即 3/3 * 100 = 100%
他已经出现在网格上(尽管是 99%)

安德鲁有 4 笔付款和 4 条 NAEDO 记录(开始日期不同)
即 4/4 * 100 = 100%
他应该在发车区的同一个位置。

也许在后台我可以收集所有的网格位置分数并打点百分比计算。

一位客户的代表
enter image description here

最佳答案

所以这应该是关于所需的查询。我从 account_detail 中选择帐户及其分组字符串(行和列组)。我计算每个帐户的成功 paysoft 结果和每个帐户不同的 naedo 开始日期。然后我加入并聚合。然后由 Jasper Reports 在网格中旋转和显示数据。

select 
ad.escore,
ad.mscore,
sum(ps.cnt) / sum(n.cnt) * 100 as percent
from
(
select
account_no,
-- 602 becomes '595-604'
to_char(trunc(empirica_score - 5, -1) + 5, , '9999') || '-' || to_char(trunc(empirica_score - 5, -1) + 14, '9999') as escore,
-- 97 becomes '76-100'. Change the expression to group differently.
to_char(((mfin_score - 1) / 25) * 25 + 1) || '-' || to_char(((mfin_score - 1) / 25) * 25 + 25) as mscore
from account_detail
) ad
join
(
select custno, count(*) as cnt
from paysoft_result
where result = 'Successful'
group by custno
) ps on ps.custno = ad.account_no
join
(
select customer_code, count(distinct start_date) as cnt
from naedo
group by customer_code
) n on n.customer_code = = ad.account_no
group by ad.escore, ad.mscore;

关于sql - 令人惊讶的困惑(不可能的)查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25911211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com