2014-09-19 119 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',以便根據數字範圍進行排序。

相關問題