• Jeff Moden (8/19/2014)


    davidmckee (8/19/2014)


    This is the exact result...except it seems to be in MSSql...the web server runs MySql

    I did some research after copying the code into the query and receiving errors...maybe this is MS SQL and not MySql

    Does anyone know how to convert this from MSSQL to MySql?

    Again assuming this is the difference....

    This was the error when I run it

    MySQL said: Documentation

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH

    cteWinLose AS

    ( --=== Calculates the wins/losses using a CROSS APPLY to "' at line 1

    It would appear that you need to convert the CTEs (the WITHs) to FROMs as "derived tables".

    I've had a bit of a play with this in SQLFiddle and found a couple of views worked well for me. Here's what I came up with, thanks to Jeff for the setup.

    SQL Fiddle