ID YEAR 1 2001 1 2002 1 20031 20041 20051 20061 20071 20082 1995 2 19962 19972 1998
然后我试过的查询:
select "ID",count("Year") "Count",Listagg("Year",',') within group (order by "Year") "Years"from ( select distinct tbl2.ID "ID",tbl1.year "Year" from table1 tbl1 join table2 tbl2 on(tbl1.tbl2ID = tbl2.ID) )group by "ID"
得到了这样的结果:
ID Count Years1 8 2001,2002,2003,2004,2005,2006,2007,20082 4 1995,1996,1997,1998
ID Count Years1 3 2001,20031 3 2004,20061 2 2007,20082 3 1995,19972 1 1998解决方法 使用ceil函数:
select "ID",') within group (order by "Year") "Years"from ( select tbl2.ID "ID",tbl1.year "Year",row_number() over ( partition by tbl2.ID order by tbl1.year ) rn from table1 tbl1 join table2 tbl2 on(tbl1.tbl2ID = tbl2.ID) )group by "ID",ceil(rn/3);
SQL Fiddle Demo
总结以上是内存溢出为你收集整理的Oracle SQL限制结果然后显示剩余的结果全部内容,希望文章能够帮你解决Oracle SQL限制结果然后显示剩余的结果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)