ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
ph91.de
ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
  • Software Development

Generating Rankings with counter variables in MySQL

  • 31. March 2016
  • Philipp

While programming SQL statements for ranking generation on speed-kini.de, I found out that local counter variables in SQL statements may no act as intended. Especially if you combine a counter variable with ‘order by‘in the same statement. You can fix it by wrapping your Select statement in a way that the counter variable doesn’t interfere with any ordering:

SELECT
	@runtot := @runtot + 1 AS 'Rang ',
	t.*
FROM (

			 SELECT [...]) t,
	(SELECT @runtot := 0) r;
Related Topics
  • local variable
  • mysql
  • order
  • ranking
  • speed-kini
  • sql
Philipp

Previous Article
  • Sports

Getting involved with Ski Touring

  • 31. March 2016
  • Philipp
View Post
Next Article
Speed-kini.de rankings with latest additions highlighted.
  • Software Development

Highlight newest entries in wpDataTables

  • 13. April 2016
  • Philipp
View Post

Leave a Reply

Your email address will not be published. Required fields are marked *

Dev profiles
  • BitBucket
  • Github
  • Stackoverflow
Side Projects
  • NMF
  • Speed-kini.de
  • Sudoku Solver
  • Windwarner
Archive
ph91.de
Blog by Philipp Schreitmüller

Input your search keywords and press Enter.