Hello,
I have some problem in this following query. In this query, I am taking top 5% of customers and i need to rank it accordingly(like 1,2,3,4 ....). But, I am not getting proper order in this query. Please help me .
select
t3.branch
,t1.acct_nbr
,rank(t1.acct_nbr) as rank_acct_nbr
from
(
SELECT
A.account_nbr
, A.bal_amt
FROM
(
SELECT a1.account_nbr, quantile(100,a1.bal_amt) as percentile
FROM table a1
GROUP BY a1.account_nbr
QUALIFY percentile between 0 and 4
)
) t1 (acct_nbr,balance_amt)
inner join
(
select
a.account_nbr
, a.domicile_channel_id
, a.account_type_code
, b.product_type_code
from
table1 a
inner join table2 b
on a.product_id = b.product_id
) t3(acct_nbr,branch,acct_type_code,prodt_type_code)
on t1.acct_nbr = t3.acct_nbr
I have some problem in this following query. In this query, I am taking top 5% of customers and i need to rank it accordingly(like 1,2,3,4 ....). But, I am not getting proper order in this query. Please help me .
select
t3.branch
,t1.acct_nbr
,rank(t1.acct_nbr) as rank_acct_nbr
from
(
SELECT
A.account_nbr
, A.bal_amt
FROM
(
SELECT a1.account_nbr, quantile(100,a1.bal_amt) as percentile
FROM table a1
GROUP BY a1.account_nbr
QUALIFY percentile between 0 and 4
)
) t1 (acct_nbr,balance_amt)
inner join
(
select
a.account_nbr
, a.domicile_channel_id
, a.account_type_code
, b.product_type_code
from
table1 a
inner join table2 b
on a.product_id = b.product_id
) t3(acct_nbr,branch,acct_type_code,prodt_type_code)
on t1.acct_nbr = t3.acct_nbr