1 select distinct(a.cspcode), b.ccode as code ,t_c.cname as name,t_d.cname as p01,to_char(a.cclicktime,'yyyy-mm-dd'),count(*) from t_spead_clickqty a 2 inner join t_page_channels b on a.cspcode=b.cspcode 3 inner join t_channels t_c on t_c.ccode = b.ccode 4 inner join t_dictionary t_d on t_c.cchanneltype = t_d.ccode 5 where 1=1 and a.cclicktime>=to_date('2016-08-10','yyyy-mm-dd') and to_date('2016-09-10','yyyy-mm-dd')>=a.cclicktime 6 group by a.cspcode,t_c.cname,b.ccode,t_d.cname,to_char(a.cclicktime,'yyyy-mm-dd') 7 order by count(*) desc
1. 前10,可以用top 10,或者row_number来解决
select * from ( select distinct(a.cspcode) as id, b.ccode as code ,t_c.cname as name,t_d.cname as p01,to_char(a.cclicktime,'yyyy-mm-dd') as p02,count(*) as p03 from t_spead_clickqty a inner join t_page_channels b on a.cspcode=b.cspcode inner join t_channels t_c on t_c.ccode = b.ccode inner join t_dictionary t_d on t_c.cchanneltype = t_d.ccode where 1=1 and a.cclicktime>=to_date('2016-08-10','yyyy-mm-dd') and to_date('2016-09-10','yyyy-mm-dd')>=a.cclicktime group by a.cspcode,t_c.cname,b.ccode,t_d.cname,to_char(a.cclicktime,'yyyy-mm-dd') order by count(*) desc ) where rownum<=10
显示前十条
楼主的意思肯定是说程序里面拼sql的时候取前十吧?如下:
string sql="select top (@count) distinct(a.cspcode)...";
int count=10;
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@count",SqlDbType.Int)
};
paras[0].Value = count;