Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
Transposing SQL tables - code-flow.club | Q&A

Transposing SQL tables


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
16 views
faced with the task to transpose a table (turn 90 degrees).
there are columns
A | B | C
1 | 2 | 3
4 | 5 | 6

bring
A 1 4
B 2 5
C 3 6

on the Internet write
"my very strong advice: don't try to do this with SQL"
and a couple of rather "strange" options

What would you recommend?
by | 16 views

7 Answers

0 like 0 dislike
It is not entirely clear what type of data, but in any case fashionable simple enough to solve by using Dynamic SQL.
by
0 like 0 dislike
A | B | C
1 | 2 | 3
4 | 5 | 6
\r
bring
A 1 4
B 2 5
C 3 6
by
0 like 0 dislike
A | B | C
1 | 2 | 3
4 | 5 | 6
turn 90 degrees to the left:
3 6
B 2 5
A 1 4
\r
right:
4 1 A
5 2 B
6 3 C
\r
Transposition — replacing columns with rows, and not turn!
by
0 like 0 dislike
If the data are not over many and the task of single — procedure is very simple:
1. To consider everything.
2. Transpose.
3. To record everything.
by
0 like 0 dislike
I wonder where such a task.
\r
By the way, the DBMS essentially are able, in some sense, table transpose. This is called "index".
by
0 like 0 dislike
It is unlikely this will help, but in MS-SQL'e this is done with the help of the function PIVOT. Perhaps Google on "pivot in MySql" will help
by
0 like 0 dislike
when dumb muscle is to learn how to do
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,181 users