Skip to content
Advertisement

on SQL can I have a ratio column based on a count of multiple parameters?

On this query here, I get the following result in the image provided below. However I want to take it a step further and turn the count into a ratio of wins / total wins.

However when I use the second query (at the bottom) I get an error invalid use of the group function.

To explain, the count is based on a grouping of each unique combination of columns in the query

Can someone explain what i’m doing wrong please?

enter image description here

Advertisement

Answer

You need to use COUNT(*) as a subquery (if there is a where clause then it needs to match in both queries):

Edit:

If using MySQL 8 or later you can use window functions. Your original query will work after correcting the syntax:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement