I have worked a bit in pivot/unpivot in Oracle SQL but this one seems little complex and need some help here. the below is my table design year Comp_A_prev_yr_due_ct Comp_A_prev_yr_due_amt Comp_A_curr_yr_due_ct Comp_A_Curr_yr_due_amt 2019 100 1000 101 1001 like this I have multiple companies as columns (each as a set of 4) and the report needs to be kinda be reader
Tag: unpivot
UNPIVOT Holiday Hours
I have a table, that keeps track of store holiday hours: This is a highly oversimplified table. There’s about 30 columns horzontially consisting of store operating hours by date – It continues (DATE3, TIMES3, DATE4, TIMES4, etc). I need to unpivot the values vertically, ensuring the date and time values are on the same record. (NOTE: Once I figure out
Postgres, split single row into multiple rows
I’ve got a table with columns like: I want to return: I ended out writing a large query using 3 unions like this, but this does not seem right: Is there a way to do this without the mess? Seems like I’m missing something really obvious. Answer In Postgres, you can efficiently unpivot the columns to rows with a lateral
Insert 2 select in same insert SQL
i have a problem, i would like use 2 select to insert in new table but i don’t know if it’s possible… my code : I would like insert the second part ( select COLONNE01….) in the first part instead of “INSERT HERE” DATA OLD TABLE : COLUMNS 1 (“PKID1″, one”,”two”,”three”) COLUMNS 2 (“PKID2″,”one”,”two”, “three”) New TABLE : (PKID1, one,
PostgreSQL, summing multiple date columns over multiple rows
Let’s assume the following table: CREATE TABLE assumption ( datetime_1 TIMESTAMP, datetime_2 TIMESTAMP, datetime_3 TIMESTAMP); Now I want to know the total amount of times a month is set in any row …
TSQL PIVOT/UNPIVOT Multiple Summarized Columns
Seems this is a popular topic but I can’t seem to replicate other answers. I have data that is already summarized by month/year for multiple categories. What I’m trying to get is this Here’s the query to provide the data I’ve used PIVOT a bunch of times, but with a single “category” of data. I can’t seem to get anything
logic to create more rows in sql
I have a table1 that I wanted to transform into the expected table. Expected table logic for columns: cal: comes from cal of table1. ID comes from the ID of table1. code: this is populated with lp or fp depending upon if we have a value in f_a then we create a new record with fp as code. corresponding to
SQLite How to calculate a difference between two variables of the same table [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I am pretty new to SQL and I can’t figure out how to sum the amounts (in_amount – out_amount) per asset in the pantry considering
Max and Avg debt days over a period of time
I have invoices pending payment, every invoice has two dates, first when the invoice is required to pay and the other when the invoice is paid. I want to know in a period of time the max debt and the …
I’m looking for a pair of SQL functions (MS SQL Server) that will return the MAX or MIN of a list of dates
I’m looking for a pair of SQL functions that will return the MAX and MIN value of a list of dates (or, alternatively, the MAX and MIN of two dates – I can then stack the calls to handle the whole list)…