- 论坛徽章:
- 0
|
嗯,跳出了常规思路,值得借鉴,但是效率上并不是最强
mysql> SET @scorenow =99999 ;
Query OK, 0 rows affected (0.00 sec)
mysql> SET @rank =0 ;
Query OK, 0 rows affected (0.00 sec)
mysql> SET @total =0 ;
Query OK, 0 rows affected (0.00 sec)
mysql> SET @paper_id =0 ;
Query OK, 0 rows affected (0.00 sec)
mysql> create table cenalulu
-> SELECT
-> paper_id,
-> class_student_id,
-> IF (
-> (
-> IF (
-> paper_id = @paper_id , @total := @total +1 , (
-> @total :=1
-> AND @rank :=1
-> AND @paper_id := paper_id
-> )
-> )
-> AND score < @scorenow
-> ),
-> @rank := @total , @rank := @rank
-> ) AS mrank,
-> (
-> @scorenow := score
-> ) AS mscore
-> FROM tmp_subject_score
-> ORDER BY paper_id, score DESC;
Query OK, 24000 rows affected (0.11 sec)
Records: 24000 Duplicates: 0 Warnings: 0
mysql> create table xlwang
-> select A.class_student_id,A.paper_id,A.score,B.OrderNo
-> From tmp_subject_score A ,
-> ( select X.paper_id,X.score,Sum(Y.CC)-Y.CC+1 as OrderNo
-> From (select distinct paper_id,score From tmp_subject_score ) X ,
-> (select paper_id,score,count(*) as CC From tmp_subject_score
-> group by paper_id,score ) Y
-> where X.paper_id=Y.paper_id and X.score <= Y.score
-> Group by X.paper_id,X.score ) B
-> where A.paper_id=B.paper_id and A.score=B.score;
Query OK, 24000 rows affected (0.31 sec)
Records: 24000 Duplicates: 0 Warnings: 0 |
|