2014-09-19 89 views
0

我可以在查询中单独对两列进行排序,以便两者都完美匹配?对数字范围列进行排序

给出例如:

QUERY

select 
    ad.escore, 
    ad.mscore, 
    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 escore, 
    cast(((mfin_score - 1)/25) * 25 + 1 as text) || '-' || cast(((mfin_score - 1)/25) * 25 + 25 as text) as mscore 
    from account_details 
) ad 
join 
(
    select custno, count(*) as cnt 
    from paysoft_results 
    where result = 'Successful' 
    and resultdate >= '13/08/2014' 
    and resultdate <= '12/19/2014' 
    group by custno 
) ps on ps.custno = ad.account_no 
join 
(
    select customer_code, count(distinct start_date) as cnt 
    from naedo 
    and start_date >= '13/08/2014' 
    and start_date <= '12/19/2014' 
    group by customer_code 
) n on n.customer_code = ad.account_no 
group by ad.escore, ad.mscore; 

返回结果

enter image description here

REPORT GRID

enter image description here

是否有可能有完美的升序列和行?

+0

尝试在查询结尾处将GROUP BY放在GROUP BY后面,并且您想要订购的字段 – mikeyq6 2014-09-19 10:17:00

回答

1

列和行实际上是在报表中排序的。您正在对字符串值进行排序,其中'51 -75'大于'101-125',因此看起来不正确。

您需要将'51 -75'格式化为'051-075',以便根据数字范围进行排序。