D
D
Davlik2016-11-09 00:15:29
SQL
Davlik, 2016-11-09 00:15:29

How to use string as column name?

There is a table that looks like this:
first | second | third
-----------------------
first | second | third
ab | ba | cd
1 | 2 | 3
Is it possible to somehow change the names of the first, second, third columns to ab, ba, cd with one query?
It is difficult to do this manually, because there are many such columns in the table .
UPD .
Maybe something interesting will tell you how best to implement the work with this table?
198d7a2aebfb4f47981dce42a95e40a4.jpg
Now I want that where there is a group number in the 3rd line, this number could be used as a column name. Or is it better to transpose the table?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romy4, 2016-11-09
@romy4

really replace in the table or in the output? both can be

D
Dmitry Eremin, 2016-11-09
@EreminD

SELECT first AS ab, second AS ba, third AS cd FROM table

This will substitute the desired values ​​in the column names

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question