O
O
one__for__one2016-12-08 06:17:44
SQL
one__for__one, 2016-12-08 06:17:44

How to change the display of data in a SQL query?

There is a request
select idSklada, kolVoDetalei from magazin
The problem is that warehouses are returned in a column one under the other, but it is required that they be in a row.
Now
idSklada || kolVoDetalei
1 || 3
1 || 4
1 || 5
2 || 3
2 || 4
3 || 5
Requires
idSklada || kolVoDetalei -----------idSklada || kolVoDetalei --------------idSklada || kolVoDetalei
---------1 || 3--------------------------------- 2 || 3------------------------------------ 3 || 5
---------1 || 4 ---------------------------------2 || 4
----------1 || 5
It is possible through subqueries:
Make 3 subqueries, and then combine them into one.
But the problem is that the user selects the number of warehouses on the form. It will be necessary to generate requests in C#. This is not a problem for me, I can write, but I want to write so that the code is beautiful.
Is it possible to do this in some SQL function?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2016-12-08
@one__for__one

PIVOT
but it is better to specify the dialect of SQL.

A
ALIMOEdm, 2016-12-08
@ALIMOEdm

Try GROUP_CONCAT

O
one__for__one, 2016-12-09
@one__for__one

1a55385f765e47149acd6ae1e11506fc.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question