Unfortunately there is no way to do it via just one query. You should parse output of query using some external script. If you do select with “\G” at the end instead of “;”, you will receive data in vertical format, something like this:
*************************** 1. row ***************************
user_id: 1
quiz_id: 1
activity_date: 2008-02-02 00:00:00
*************************** 2. row ***************************
user_id: 1
quiz_id: 3
activity_date: 2008-02-02 00:00:00
*************************** 3. row ***************************
user_id: 1
quiz_id: 9
activity_date: 2008-02-02 00:00:00
And it will be not difficult to process such output using some perl script to build a table with swapped rows<->columns.
EXPLAIN SELECT Errorcode , count(*) AS “Count”, ClientName FROM customer_profile_SMM WHERE ClientName IN (SELECT DISTINCT a.ClientName FROM customer_profile_SMM a) GROUP BY Errorcode,ClientName;
EXPAIN SELECT ABC , count(*) AS “Count”, XYZ FROM profile WHERE XYZ IN (SELECT DISTINCT a.XYZ FROM profile a) GROUP BY ABC,XYZ
±—±-------------------±---------------------±------±- -------------±------------±--------±-----±--------±---- --------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
±—±-------------------±---------------------±------±- -------------±------------±--------±-----±--------±---- --------------------------------------+
| 1 | PRIMARY | customer_profile_SMM | index | NULL | Errorcode_2 | 65 | NULL | 3785102 | Usingwhere; Using index |
| 2 | DEPENDENT SUBQUERY | a | index | NULL | Errorcode_2 | 65 | NULL | 3785102 | Usingwhere; Using index; Using temporary |
±—±-------------------±---------------------±------±- -------------±------------±--------±-----±--------±---- --------------------------------------+