I'm trying to create a pivot table based on 200+ different values. A friend has prepared a working example of what I need in T-SQL but the ROW_NUMBER function isn't available in MySQL and I have been unable to translate this to do what I need.
The UniqueTally value is a count of how many distinct values for Word have appeared before this one. The example below shows that when "a" appears again in row 3, this doesn't increase the UniqueTally as it was also in row 1.
My data looks like this:
Table "Word"
| WordID | MemberID | Word | UniqueTally
| 1 | 1 | a | 1
| 2 | 1 | b | 2
| 3 | 1 | a | 2
| 4 | 2 | c | 1
| 5 | 2 | d | 2
| 6 | 2 | e | 3
I have 200+ Members and I'm trying to create a table that shows how the Unique count increases across all members. I.e. Aligning the UniqueTally value by Member. Word index is the row entry number for this member
| WordIndex | UniqueTallyMember1 | UniqueTallyMember2 | etc
| 1 | 1 | 1
| 2 | 2 | 2
| 3 | 2 | 3
A friend kindly generated the code I need in T-SQL :
/* Return the data */
SELECT
[WordSpoken]
,[182] AS [Mem182_UniqueTally]
,[200] AS [Mem200_UniqueTally]
FROM (
SELECT [WordSpoken], [MemberID], [UniqueTally]
FROM (
SELECT
ROW_NUMBER() OVER(PARTITION BY [MemberID] ORDER BY
[WordID]) AS [WordSpoken]
,[MemberID]
,[UniqueTally]
FROM [dbo].[ut_test]
) AS [test]
) AS [tbl]
PIVOT (MAX(UniqueTally) FOR MemberID IN ([182],[200])) AS [pvt]
GO
This uses only 2 MemberID values but it works in as much as aligning the Unique values. I need something similar in MySQL that also takes in the MemberID dynamically. Is this possible?
I've tried Googling and searching other similar posts about this but I'm unable to translate these directly to my problem.