Finding a unique value from 2 columns and then a ratio of those values

flip66

I have a table with the columns id, player1, and player2. The ID's for a player can be in either of the two columns. I need to find all the unique ID's in column player1 and column player2 combined. Then I need to also find the amount of times each player appears in each column. Finally I want to order it by the ratio of column player1 / column player2.

For instance, I have the following values in the table.

1 103 101

2 103 111

3 232 103

4 223 111

My query would return..

Player 223: 1/0

Player 232: 1/0

Player 103: 2/1

Player 101: 0/1

Player 111: 0/2

I know for the unique IDs I can do something like this

select 
(SELECT group_concat(DISTINCT player1) FROM table) as player1,
(SELECT group_concat(DISTINCT player2) FROM table) as player2

and I know for the order I can do something like this

ORDER BY player1 / player2 DESC

I'm really just having a hard time figuring out what to do once I get the unique ID and then try to get the ratios outputed and sorted

A. Zalonis

Try this

select player1,player2, CONCAT('Player',IF( (select count(DT.player1) from table as DT where MT.player1 = DT.player1) > 0, player1,player2),':', (select count(DT.player1) from table as DT where MT.player1 = DT.player1), ' / ', (select count(DT.player2) from table as DT where MT.player2 = DT.player2) )  
from table MT
where player1 != player2
group by palyer1,player2
order by (player1/IF(player2 is not null and player2 != 0,player2,1) desc

I hope it helps you

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding unique values between 2 Excel columns

From Dev

Finding unique set of values across columns [SQL]

From Dev

Finding the values from same table that have value 1 and 2 but not 3

From Dev

Get the non unique values from 2 columns using formula

From Dev

Finding unique columns

From Dev

Finding unique columns

From Dev

Sql-find duplicate values of two columns and display all values of "column 1" and unique value of "column 2"

From Dev

Finding unique values in Array

From Dev

Finding unique values in Array

From Dev

Select Unique Values from Different Columns

From Dev

Select Unique Values from Different Columns

From Dev

Finding unique values from array across three tables

From Dev

From Pandas Dataframe find unique values in column and see if those values have the same values in another column

From Dev

Android, sqlite database finding two values in the two columns and the resulting value

From Dev

list of unique value from two columns

From Dev

is there a way to read values from a file int an array and initialize those value?

From Dev

How to check if cell value is greater than X, get the difference from those 2 values and add to the next cell in Excel?

From Dev

Swift 2 finding variable name from value

From Dev

Finding the average of columns from nested lists in a dictionary's value

From Dev

Finding the average of columns from nested lists in a dictionary's value

From Dev

Finding max value of multiple columns from multiple tables to update Sequence

From Dev

Finding combinations of per-column row values such that columns have unique rows

From Dev

Select rows from dataframe with unique combination of values from multiple columns

From Dev

Assign unique value out of multiple columns (allowed values)

From Dev

Selecting columns using specific patterns then finding sum and ratio

From Dev

Finding rows with multiple values in the columns

From Dev

Need help MSSQL query to bring table with two columns into one showing unique value of field 1 and corresponding values in field 2 (in that order)?

From Dev

How to map different values from 2 sets in clojure based on unique value

From Dev

Finding max value in array with increasing values from either side of an index

Related Related

  1. 1

    Finding unique values between 2 Excel columns

  2. 2

    Finding unique set of values across columns [SQL]

  3. 3

    Finding the values from same table that have value 1 and 2 but not 3

  4. 4

    Get the non unique values from 2 columns using formula

  5. 5

    Finding unique columns

  6. 6

    Finding unique columns

  7. 7

    Sql-find duplicate values of two columns and display all values of "column 1" and unique value of "column 2"

  8. 8

    Finding unique values in Array

  9. 9

    Finding unique values in Array

  10. 10

    Select Unique Values from Different Columns

  11. 11

    Select Unique Values from Different Columns

  12. 12

    Finding unique values from array across three tables

  13. 13

    From Pandas Dataframe find unique values in column and see if those values have the same values in another column

  14. 14

    Android, sqlite database finding two values in the two columns and the resulting value

  15. 15

    list of unique value from two columns

  16. 16

    is there a way to read values from a file int an array and initialize those value?

  17. 17

    How to check if cell value is greater than X, get the difference from those 2 values and add to the next cell in Excel?

  18. 18

    Swift 2 finding variable name from value

  19. 19

    Finding the average of columns from nested lists in a dictionary's value

  20. 20

    Finding the average of columns from nested lists in a dictionary's value

  21. 21

    Finding max value of multiple columns from multiple tables to update Sequence

  22. 22

    Finding combinations of per-column row values such that columns have unique rows

  23. 23

    Select rows from dataframe with unique combination of values from multiple columns

  24. 24

    Assign unique value out of multiple columns (allowed values)

  25. 25

    Selecting columns using specific patterns then finding sum and ratio

  26. 26

    Finding rows with multiple values in the columns

  27. 27

    Need help MSSQL query to bring table with two columns into one showing unique value of field 1 and corresponding values in field 2 (in that order)?

  28. 28

    How to map different values from 2 sets in clojure based on unique value

  29. 29

    Finding max value in array with increasing values from either side of an index

HotTag

Archive