DEV Community

Jonah Blessy
Jonah Blessy

Posted on

Number Guessing Game

  1. Show an option to get the details from the leaderboard db.
  2. And find a way to sort it based on difficulty and attempts (Either Ascending or Descending)

  • For the guessing game algorithm, let us consider that some users have played the game and we got their result. The results are put in a database with the parameters like user id, username, attempts, difficulty level, time taken to guess.
  • To get these details from leaderboard db we can use either * to get all details or select column names. For testing purposes i'm using select *.
select * from leaderboard;
Enter fullscreen mode Exit fullscreen mode
  • Now to sort it based on difficulty, we can make use of the order by clause. I want the list in descending order so i will use order by column_name desc in my syntax.
select userid,difficulty,attempts from leaderboard order by difficulty desc, attempts;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)