Skip to content

Tag: transpose

converting rows to columns using oracle sql

I’m trying to convert rows into columns using the following sample: LVL COL_VALUE TABLE_SRC 16 INT: ADDRESS_LINE_2:NULL INT 16 BASE: ADDRESS_LINE_2:X BASE 17 INT: ADDRESS_LINE_3:NULL INT 17 BASE: ADDRESS_LINE_3:X BASE The output should be: INT BASE INT: ADDRESS_LINE_2:NULL BASE: ADDRESS_LINE_2:X INT: AD…

Transpose row to column in SQL Server

I have a table like below: The first row is the header. Now, I would like to transpose table into this I have tried unpivot but the result is not desired table. Thanks in advance, Answer I recommend using cross apply to unpivot and then aggregation: I much, much prefer this over pivot/unpivot. Why? APPLY impl…

Oracle SQL Pivot with Conditions convert rows to columns

I have the a table ITEM_SF with the following data I want to convert the data into Columns with a few conditions: My desired result is to show Charges, Discounts , Amount Paid and Tax Charges include (BookFees, HealthFees,RegistrationFees,SSCFees,TuitionFees,GeneralFees) Charges , Discount is Sum of ITEM_AMT …

SQL Transpose for timestamps

I want to ask, how to make output below : from data like this below : with rules the ‘Clock_in’ is the earliest and ‘Clock_out’ is the latest one of the ‘Timestamps’ group by ‘NIP’ Answer If you are using SQL server you can make sure of Cast and group by. output…

How to merge columns and transpose in SQL?

I’m working with a custom DBMS (compliant with SQL 2011 Standard), and am trying to combine multiple columns into a single column like so, but am struggling with the syntax: Current table: Desired query output: I’ve tried various IF and CASE statements, but have hit a wall. Any help would be appre…

Easy table transpose in hive

I need to transpose my table. Now i have that type of table: But i want to get the next result How should i transpose my table for achieving this result? Answer Use case statements with min() or max() aggregation: