select ROW_NUMBER() OVER(ORDER BY price ) AS Row,Code,price from
(
select Code,price,count(*) as c_num
from tb_xxxx
group by Code
)a where c_num > 1 order by price
select row_number() OVER (order by hs_no asc,value_usd desc) AS 'NO',hs_no,month,country_code,value_usd from
/*2*/
(select
hs_no,month,country_code
,sum(value_usd) as value_usd
from
/*1*/
(SELECT substring(HS_NO,1,8) as hs_no
,[COUNTRY_CODE]
,substring(month,1,4) as month
,[QUANTITY]
,[VALUE_THB]
,[VALUE_USD]
,[QUANTITY_ACCUMULATE]
,[VALUE_THB_ACCUMULATE]
,[VALUE_USD_ACCUMULATE]
FROM [mocdtn_share].[dbo].[IMEX_HS_F_imPORT] )a
where month in ('2015') group by hs_no,month,country_code) b
order by hs_no asc,value_usd desc