SQL数据:name num
a 10
a 20
b 15
c 15
c 25
select排列结果:name num
c 25
c 15
a 20
a 10
b 15即:先统计相同NAME的总数进行排序: A(30) B(15) C(40),那么顺序就是CAB然后C中有一个25,一个15,A中有20,10,再按降序排列的上述结果,跪求SQL``
a 10
a 20
b 15
c 15
c 25
select排列结果:name num
c 25
c 15
a 20
a 10
b 15即:先统计相同NAME的总数进行排序: A(30) B(15) C(40),那么顺序就是CAB然后C中有一个25,一个15,A中有20,10,再按降序排列的上述结果,跪求SQL``
SQL> select a.name,a.num from(select t.name,test.num,t.levels from (select name, sum(num) levels from test group by name) t,test where test.name=t.name order by t.levels desc,test.num desc)a;NAME NUM
---- ----------
c 25
c 15
a 20
a 10
b 15SQL> select * from test;NAME NUM
---- ----------
a 10
a 20
b 15
c 15
c 25
SQL> select a.name,a.num from(select t.name,test.num,t.levels from (select name, sum(num) levels from test group by name) t,test where test.name=t.name order by t.levels desc,test.num desc)a;NAME NUM
---- ----------
c 25
c 15
a 20
a 10
b 15SQL> select * from test;NAME NUM
---- ----------
a 10
a 20
b 15
c 15
c 25
inner join
(
SELECT A, Sum(B) AS amt_b FROM t_kevin_test_2 GROUP BY A ORDER BY Sum(B) DESC
)t2ON t1.a=t2.a
;
select t.name,t.num from test t,(select name,sum(num) rn from test group by name) a where t.name=a.name order by a.rn desc, t.num desc;