Oracle SQL How can I separate values from a column in two different columns?

Young Al Capone

I want to code a query to return description of some concepts and their respective price but I want to make two different columns to categorise two diferentes items categories of values. Is it possible?

SELECT b.descripcion CONCEPTO, a.cantidad, a.importe,
       c.descripcion
FROM   detalles_liquidaciones a
JOIN   conceptos b
ON    (a.codigo_concepto = b.codigo)
JOIN   tipos_conceptos c
ON    (b.codigo_tipo = c.codigo)
WHERE  a.numero_liquidacion = 13802
AND    c.descripcion IN ('HABER', 'RETENCION', 'ANTICIPO');

Output Query

I want to code something like this: Ideal query

Raphaël

Could this work ? ( Perhaps there's a better solution, it feels a bit tricky... litterally "switching" ):

SELECT Concepto ,
      (CASE
         WHEN description LIKE 'HABER' THEN
          importe
         ELSE
          NULL
       END) haberes,
       (CASE
         WHEN description LIKE 'HABER' THEN
          cantidad
         ELSE
          NULL
       END) cantidad,
       (CASE
         WHEN description LIKE 'RETENCION' OR description LIKE 'ANTICIPO' THEN
          importe
         ELSE
          NULL
       END) retenciones
  FROM (SELECT b.descripcion concepto, a.cantidad, a.importe, c.descripcion
          FROM detalles_liquidaciones a
          JOIN conceptos b
            ON (a.codigo_concepto = b.codigo)
          JOIN tipos_conceptos c
            ON (b.codigo_tipo = c.codigo)
         WHERE a.numero_liquidacion = 13802
           AND c.descripcion IN ('HABER', 'RETENCION', 'ANTICIPO'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I separate a string into columns, if I have multiple rows and the strings are of different length in SQL?

How can I perform aggregation across two separate columns in SQL?

How can I create a new column of values based on the grouped sum of values from two other columns?

How can I select unique values from several columns in Oracle SQL?

How can I split a single string into two different columns sql

Oracle 11g how I can group values from two different columns

How to separate values (delimiter separated) as different columns from SQL Server table having multiple rows?

Excel - Separate values from column into two columns

How to count two separate columns from two different tables?

How can I add up all the values in a table column generated from an Array list with two separate objects?

How can I find the cumulative sum from the different two columns?

I want to select two different columns from two tables based on another column by SQL

How can I combine values from two columns?

#Excel - How do I compare two columns of different length and extract the difference in a separate column?

How can I return two different values from the same column in a SQL Join?

How to separate same numbers from one column in different different columns?

SQL - Split values from one column into two separate columns

How to concatenate two values from different columns into a single column

How can I fill a column based on a difference between the values of two different columns, using groupby?

How can I count the amount of values in different columns in oracle plsql

How can I create a column target based on two different columns?

After comparing two columns, how can I remove unique values in one column with its values in other different columns in R

how can i separate the two values

How can I write an excel formula to count the number of times values in two separate columns are the same on the same row

How can I separate the data frame of one column into two columns in R?

how to count two different values from same column in oracle

How to return values of two date ranges, from the same date column and value column, in two different columns as a result?

How can I create a new column with values assigned based on conditions from rows in two columns?

How to separate in two different columns values that are located on two different columns as pivot format