H
H
hydra_132016-07-28 23:05:01
MySQL
hydra_13, 2016-07-28 23:05:01

What is the correct way to write such a SQL query?

There are 2 tables. Such a query is required that will receive the combined data from two tables, while the fields (columns) of the resulting table will be the values ​​​​of one of the tables (an example of which I want is approximately shown in the picture, it is difficult to describe). Please help anyone who can. Where to dig? What will be applied? Which way to look? If there is an example - I will be grateful! ))
f88dc0954873402fbf7694e7ceee7676.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Draconian, 2016-07-29
@hydra_13

The task nontrivial, it is the best of all to write procedure.
Oracle has PIVOT and UNPIVOT functions (data transposition), they have implementations for older versions as separate procedures, try digging in that direction.
And in general, google transposition in MySQL, for example: buysql.com/mysql/14-how-to-automate-pivot-tables.html

A
Alex, 2016-07-29
@streetflush

Select
(select a1 from t1 where t1.id = t2.a1) as 1
(select a2 from t1 where t1.id = t2.a2) as 2
(select a3 from t1 where t1.id = t2.a3) as 3
from t2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question