SQL查询以获得具有最高赔率的博彩公司

时间:2010-07-15 09:23:02

标签: sql mysql

我尝试解决sql问题但没有成功,我认为你可以给我一个很好的答案。

我的表格如下:

league_id|style|bookmaker|hometeam|awayteam|odd1|oddX|odd2|
-----------------------------------------------------------
premier  |1X2  |bet365   |arsenal |chelsea |2.50|3.20|2.30|
-----------------------------------------------------------
premier  |1X2  |unibet   |arsenal |chelsea |2.40|3.00|2.00|
-----------------------------------------------------------
premier  |1X2  |ladbrokes|arsenal |chelsea |2.60|3.20|2.10|
-----------------------------------------------------------
premier  |1X2  |bet24    |arsenal |chelsea |2.30|3.40|2.10|
-----------------------------------------------------------

odd1 =主队获胜,odd2 =客队获胜,oddX =平局

渴望输出:

Premier League Odds:

team    |AVERAGE|BEST|BEST ODDS BOOKMAKER|
-----------------------------------------
arsenal | 2.45  |2.60| ladbrokes          |
-----------------------------------------     
chelsea | 3.20  |3.40| bet24              |
-----------------------------------------     
Draw    | 2.12  |2.30| bet365             |
-----------------------------------------     

您可以在此处查看实时示例:http://www.wsn.com/football/football-odds/

提前多多感谢。

1 个答案:

答案 0 :(得分:3)

根据您的SQL方言,如果我正确理解数字的含义,那么在这些行中使用子查询可能就是您要查找的内容:

SELECT 
    tt.hometeam as team, 
    avg(tt.odd1) as average,
    max(tt.odd1) as best, 
    tt.bookmaker as best_odds_bookmaker
FROM
    2_team_table tt
INNER JOIN
    (
        SELECT
            bookmaker as maxbookie
        FROM
            2_team_table 
        ORDER BY
            odd1 desc
        LIMIT 1
    ) as a
    ON tt.bookmaker = a.maxbookie
UNION ALL
   ..... ( same thing with awayteam and odd2 )
UNION ALL
   ..... ( same thing setting the first col to "Draw" and using oddX )

但真的你在使用某种脚本语言做这样的事情要好得多,如果你的桌子只包含两个团队,一个事件,这是非常不现实的,它只会像这样工作。