0

There is a table T with two columns C1 and C2. The data is as below:

C1 C2
1   4
2   5
3   6

display the result as :

1 2 3
4 5 6

I could not figure this out. I was thinking GROUP BY, but this isn't correct

SELECT * FROM table T GROUP BY c1 = 1, c1 =2 , c1 = 3

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Sol
  • 949
  • 1
  • 11
  • 23
  • I think column `C1` should have more than 3 kinds of value? If yes, like this table pivot in mysql, you have to use dynamic sql query. – Blank Apr 26 '17 at 02:39
  • I am studying for an interview and this was their question... looks easy but there is something to it. I will look up pivots. :) – Sol Apr 26 '17 at 02:40
  • I think its not the job of SQL. Your "display result" is "print field C1 of all records of the table" and then "print field C2 of all records of the table". – Ken Cheung Apr 26 '17 at 02:42
  • Take a look of [http://stackoverflow.com/questions/7674786/mysql-pivot-table](http://stackoverflow.com/questions/7674786/mysql-pivot-table). – Blank Apr 26 '17 at 02:42
  • Possible duplicate of [MySQL pivot table](http://stackoverflow.com/questions/7674786/mysql-pivot-table) – Blank Apr 26 '17 at 02:44

0 Answers0