+---------+-------------------+------+------+
| NAME | TITLE | SIZE | RANK |
+---------+-------------------+------+------+
| A | Hippo | H | 1 |
| A | Hippo | M | 1 |
| A | Hippo | H | N/A |
| A | Hippo | H | 1 |
| A | Hippo | H | N/A |
| B | Snail | H | 1 |
| B | Snail | M | 1 |
| B | Snail | L | 1 |
| C | Dog | H | 1 |
| C | Dog | M | 1 |
+---------+-------------------+------+------+
Example of exact data pulled from above
+---------+-------------------+------+------+
| A | Hippo | H | 1 |
| A | Hippo | M | 1 |
| A | Hippo | H | N/A |
| A | Hippo | H | 1 |
| A | Hippo | H | N/A |
+---------+-------------------+------+------+
Points are as follows:
H = 70 points
M = 20 points
L = 10 points
- Hippo has 4
Hin size column. Hin total can equal 70.- Therefore 70/4 = 17.5
- This means each single
Hcan only have 17.5 points. - Points are aquired if ‘Rank’ is present.
- Hippo has only two ‘Rank’ present.
- Therefore Hippo gains (17.5)x(2)=35 points.
- Hippo also has an
Mpresent in ‘size’ column. - Therefore
M= 20/1 =20. - Therefore hippo gains 20 points.
- Hippo has no
Lin size column. - Therefore no points gained.
- Which totals 35 (from
H) + 20 (fromM) + 0 (fromL) = 55.
Desired output
+---------+----------+-------+
| NAME | TITLE | SCORE |
+---------+----------+-------+
| A | Hippo | 55 |
| B | Snail | 100 |
| C | Dog | 90 |
+---------+----------+-------+
How do you do this type of complex scoring/variable handling in MySQl
after a complex sub select and joins, here is the result you are expecting: