首页 新闻 会员 周边 捐助

【急】[在线等]PLSQL 查询得到前十条 伪列 加上排名

0
悬赏园豆:100 [已关闭问题] 关闭于 2016-09-19 09:06
复制代码
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
复制代码

角儿-的主页 角儿- | 初学一级 | 园豆:104
提问于:2016-09-14 10:57
< >
分享
所有回答(3)
-1

1. 前10,可以用top 10,或者row_number来解决

sueris | 园豆:202 (菜鸟二级) | 2016-09-14 17:46
1
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

显示前十条 

角儿- | 园豆:104 (初学一级) | 2016-09-14 17:49
-1

楼主的意思肯定是说程序里面拼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;

八八。 | 园豆:139 (初学一级) | 2016-09-15 13:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册