DEV Community

Jarvish John
Jarvish John

Posted on

Number guessing game

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

  • Let us consider that some users have played the guessing game and we got their result. The results are in a database with details like user_id, user_name, 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.
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 have written query to display difficulty and attempts in ascending order.
select user_id, difficulty, attempts from leaderboard order by difficulty, attempts;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)