Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4542414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:23:14+00:00 2026-05-21T15:23:14+00:00

I’m creating a video ranking website. Each video goes up against another video in

  • 0

I’m creating a video ranking website. Each video goes up against another video in a match up. Then the user moves forward to the next matchup.

The following query returns results sorted by win loss ratios.

SELECT v.id, v.wins, v.loses, v.wins / v.loses AS win_loss_ratio
FROM video
WHERE v.id NOT 
IN (
SELECT h.competitorid
FROM video AS v, comphistory AS h
WHERE v.id = h.id
)
ORDER BY win_loss_ratio DESC 
LIMIT 0 , 2

Results look like this:

id      wins        loses       win_loss_ratio
73      7       2           3.5000
104     5       2           2.5000

I’m trying to figure out a way to pair videos similar to the swiss tournament method. http://en.wikipedia.org/wiki/Swiss-system_tournament

It works by pairing the top half with the bottom half. For instance, if there are eight videos returned my query I would like it arrange so that video number 1 is paired with number 5, number 2 is paired with number 6 and so on.

Does anybody have any suggestions to modify my query to arrange videos in that order?

**Update I was able to figure out how to perform query that selects one video with a high win/loss ratio and one video with a low win/loss ratio. The comphistory table keeps track of each video so they don’t go against each other twice.

SELECT videos. * 
FROM (
    SELECT videos.id, videos.wins/videos.loses as win_loss_ratio 
    FROM videos
    WHERE 
    videos.videoid NOT IN (
        SELECT h.id FROM videos AS video, comphistory as h WHERE video.id = h.id
        )
    ORDER BY win_loss_ratio ASC 
    LIMIT 0 , 1
) videos
UNION SELECT DISTINCT videos. * 
FROM (
    SELECT videos.id, videos.wins/videos.loses as win_loss_ratio 
    FROM videos
    WHERE 
    videos.videoid NOT IN (
        SELECT h.id FROM videos AS video, comphistory as h WHERE video.id = h.id
        )
    ORDER BY win_loss_ratio DESC 
    LIMIT 0 , 1
) videos

Thanks,
Tegan Snyder

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:23:15+00:00Added an answer on May 21, 2026 at 3:23 pm

    Ranking the players by score, and pairing player 2N-1 with player 2N will be about as far as you can get in the SQL statement.

    Outside the table, you will have to record who each player has played, and which round, so they don’t play each other again. For chess you will have to record if the player was black or white, so that you can reduce the number of people who have to play the same colour twice running and elliminate three-in-a-row scenarios. If you have an odd number of players, you will have to record who has sat out a round and been given a “bye”, so that they are not picked again.

    I suggest you just read the data in to a table, and sort it such that you leave equal scores in a random order. Then (if required) remove a player at random to sit out this round. You will be left with a list of players, who might be paired up (1,2)(3,4)(5,6)..etc. however this simple method may fail becasue the pair have met before, or it would create a clash of the colour rules etc.. When this happens, you need a way to search for a possible solution, widening the search space as slowly as possible, until a solution is found.

    For example, (continuing the above example), if 3 and 4 have already met, you might try (1,3)(2,4)(5,6)… and (1,2)(3,5)(4,6)… before trying other, more distant permutations such as (1,3)(2,5)(4,6)… A “best” solution will involve moving as few people from their “home” place as possible, and moving them as few steps as possible. If you can, search in a sequence so that the first solution found is acceptable.

    The alternative is to generate all permutations, check that they solve the problem and score the solution found, so you can keep the best found so far. At the end you will have the best solition, but such a search will take much longer that searching smart and stopping at the first solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.