Mysqlで順位をだす

登録日:2019.11.16

更新日:2019.11.16

Mysqlで順位をだすSQL文。

SELECT

 r1.rank_p_id,

 r1.rank_c_id,

 su1_name,

 su2_name,

 r1.rank_count,

 r1.rank_day1,

 count(r1.rank_count),

(SELECT count(r2.rank_count)

FROM article_counter1_rank as r2

WHERE r2.rank_count>r1.rank_count)+1 as rank

FROM 

    article_counter1_rank 

as r1 

left JOIN pl_su1 ON r1.rank_p_id = pl_su1.su1_id   

left JOIN pl_su2 ON r1.rank_p_id = pl_su2.su2_id  

where rank_day1 = '2019-11'

group by rank_p_id  ORDER BY rank asc

Mysqlで順位をだすSQL文。同率順位の場合は同じ順位でだすことができます。

書いた人:おりゃー

  • ○○○Works. LtdLINE
  • ○○○Works. LtdTwitter
  • ○○○Works. LtdFacebook

Mysqlで順位をだすへのコメント