im making League of Legends Api I have items in database like this database I have sql code like this to check how many times ppl bought these items in game
SELECT
Items.Item,
count(Items.Item) as repeats
FROM
(
SELECT Item0 AS Item FROM playergame
UNION ALL
SELECT Item1 AS Item FROM playergame
UNION ALL
SELECT Item2 AS Item FROM playergame
UNION ALL
SELECT Item3 AS Item FROM playergame
UNION ALL
SELECT Item4 AS Item FROM playergame
UNION ALL
SELECT Item5 AS Item FROM playergame
UNION ALL
SELECT Item6 AS Item FROM playergame
) AS Items
GROUP BY
Items.Item
ORDER BY `repeats`
This code gives me something like that:
I want to add on the right side another table with repeats but this time add to code WHERE so i made this code:
SELECT
Items.Item,
count(Items.Item) as repeats,
count(ItemW.ItemW) as Wrepeats
FROM
(
SELECT Item0 AS Item FROM playergame
UNION ALL
SELECT Item1 AS Item FROM playergame
UNION ALL
SELECT Item2 AS Item FROM playergame
UNION ALL
SELECT Item3 AS Item FROM playergame
UNION ALL
SELECT Item4 AS Item FROM playergame
UNION ALL
SELECT Item5 AS Item FROM playergame
UNION ALL
SELECT Item6 AS Item FROM playergame
) AS Items
INNER JOIN
(
SELECT Item0 AS ItemW FROM playergame
UNION ALL
SELECT Item1 AS ItemW FROM playergame WHERE Win = 1
UNION ALL
SELECT Item2 AS ItemW FROM playergame WHERE Win = 1
UNION ALL
SELECT Item3 AS ItemW FROM playergame WHERE Win = 1
UNION ALL
SELECT Item4 AS ItemW FROM playergame WHERE Win = 1
UNION ALL
SELECT Item5 AS ItemW FROM playergame WHERE Win = 1
UNION ALL
SELECT Item6 AS ItemW FROM playergame WHERE Win = 1
)AS ItemW
ON Items.Item = ItemW.ItemW
GROUP BY
Items.Item
from this sql i got this result second result of sql