Columns in mysql [duplicated]

0

I have the following sentence:

SELECT
    REF
FROM
    inv_articulo as a
    INNER JOIN inv_tipoarticulo as t ON a.TIPO_ARTICULO = t.PK_TIPO
    INNER JOIN inv_categoria as c ON c.PK_CATEGORIA = t.FK_CATEGORIA
WHERE
    c.pk_categoria = 7
order by a.ref

It gives me the following result:

-----------------
      REF 
-----------------
   OFI-0017  | 
-----------------
   OFI-0021  | 

What I want to do is to get the result in the following way:

-----------------
      REF1   |  REF2
-----------------
   OFI-0017  |  OFI-0021 
-----------------

Any help?

    
asked by Xerox 25.10.2018 в 17:01
source

1 answer

1

You can use the pivot statement: (Add a new autoincrement column call id )

SELECT
    REF
FROM
    inv_articulo as a
    INNER JOIN inv_tipoarticulo as t ON a.TIPO_ARTICULO = t.PK_TIPO
    INNER JOIN inv_categoria as c ON c.PK_CATEGORIA = t.FK_CATEGORIA
    pivot ( max(inv_categoria)
        for id in (1,2,3,4)
          )
WHERE
    c.pk_categoria = 7
order by a.ref

In this way the results will come out like this:

-------------------------
      1      |  2
-------------------------
   OFI-0017  |  OFI-0021 
    
answered by 25.10.2018 в 17:18