MySql logical order

I currently have a request:

SELECT 'id', 'clanid', 'name',
       'level', 'exp', 'warwinpercent',
       'warswon', 'warslost', 'warstied',
       'playercount', 'score'
FROM clans
WHERE warswon >= 100
ORDER BY warwinpercent DESC, warswon DESC;

Now it works, but in the end it is not as logical as I hope it can be ...

For example.

Let's say there is a series that has 99.5738% win in a war and 208 wars won. And one more that has a 100% victory in the war and 103 wars.

I would like the 99% row to be above the 100% row. Is there any way to make me work?

I have an equation:

warinpercent = warswon/(warswon+warstied+warlost)*100
order by warwinpercent
if warwinpercent are in a range of 3% then order by warswon between them.
+4
source share
1 answer

I suggest using order, for example, in How Not To Sort By Average Rating

Problem:

You need some sort of "grade" to sort.

WRONG DECISION # 1: Grade = (Positive Grade) - (Negative Grade)

# 2: = = ( )/ ( )

: =

enter image description here

:

CREATE TABLE clans(id INT, name VARCHAR(100), warswon INT, warslost INT);

INSERT INTO clans VALUES (1, 'aaa',  208, 6), (2, 'bbb', 103, 0);

SELECT id, name,warswon, warslost,((warswon + 1.9208) / (warswon + warslost) - 
                 1.96 * SQRT((warswon * warslost) / (warswon + warslost) + 0.9604) / 
                          (warswon + warslost)) / (1 + 3.8416 / (warswon + warslost)) 
       AS ci_lower_bound 
FROM clans 
ORDER BY ci_lower_bound DESC;

SqlFiddleDemo

:

╔═════╦═══════╦══════════╦═══════════╦════════════════════╗
β•‘ id  β•‘ name  β•‘ warswon  β•‘ warslost  β•‘   ci_lower_bound   β•‘
╠═════╬═══════╬══════════╬═══════════╬════════════════════╣
β•‘  2  β•‘ bbb   β•‘     103  β•‘        0  β•‘ 0.9640439675800224 β•‘
β•‘  1  β•‘ aaa   β•‘     208  β•‘        6  β•‘ 0.9401908847803808 β•‘
β•šβ•β•β•β•β•β•©β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
+7

Source: https://habr.com/ru/post/1613900/


All Articles