Anyone here know how to organize a SQLite database by, as example, kills? I mean, if each column have 3 values, "player", "kills" and "top", how to organize it like, the player with more kills get the top 1.
Common sense, but you need some natural creativity to come up with this. Code: CREATE TABLE tbl ( player TEXT, kills INTEGER ) Find player kills and rank in kills, given name: Code: SELECT kills, (SELECT COUNT(*) + 1 FROM tmp WHERE tmp.kills > kills) AS rank FROM tbl WHERE player = :s If subqueries are too confusing, do two queries (but less efficient): 1. Find the player's kills. Code: SELECT kills FROM tbl WHERE player = :s where :s is the player name 2. Find number of players with more kills than the player. Code: SELECT COUNT(*) AS count FROM tbl WHERE kills > :d where :d is the number of kills 3. Add 1 to the `count` obtained. Hint: For optimization, Code: CREATE INDEX tbl_kills ON tbl (kills)
http://www.tutorialspoint.com/sqlite/sqlite_order_by.htm http://www.techonthenet.com/sqlite/order_by.php http://stackoverflow.com/questions/...tabase-in-descending-order-for-an-android-app Links gotten from: http://lmgtfy.com/?q=how to order sqlite query