I have an issue where I would like to look for statements in a single column and each time I find them insert a new column into the mix. Im using a mysql database.
For example say I have data like this
Class Sub
-----------------
1 math
1 tech
2 math
2 english
3 math
I would like the data to be output like this:
Class math tech english
---------------------------
1 Y Y N
2 Y N Y
3 Y N N
I am trying to use CASE statements to find the values in the column, but the problem is that it will only return one result in the column for the value it finds, and i end up getting the same class repeated with a case statement for each column. Combining the case statements wont work as that still gives me a single column.
You need to wrap the
CASEexpression in an aggregate and add aGROUP BY. In this caseMAXwill work as alphabeticallyYcomes afterN(SQL Fiddle Demo)