unpivot

Combining different fees columns to create PivotTable income statement? [duplicate]

情到浓时终转凉″ 提交于 2019-11-28 06:44:48
问题 This question already has answers here : Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten', 'normalize') (3 answers) Closed last year . I have a table which records revenue for each product, split into type of revenue: price, fees, tax etc. To analyze the data I'd like to build a PivotTable to show the revenue breakdown, e.g.: So to build this PivotTable I need to somehow create an intermediate table of the following format so the PivotTable can be used: My question is,

Expand Start Date to End Date with Series of EOMONTHs

前提是你 提交于 2019-11-28 05:18:55
问题 I have a data table containing ids with a start date and end date associated with both. RowNo AcNo StartDate EndDate 1 R125 01/10/2017 30/09/2020 2 R126 01/10/2017 30/09/2018 3 R127 01/10/2017 30/09/2019 4 R128 01/10/2017 30/09/2020 I need to expand (i.e. unpivot) this table to allow one row for each eomonth between the start and end date (inclusive) for each AcNo. The row numbers are unimportant. AcNo EOMONTHs R125 Oct 17 R125 Nov 17 R125 Dec 17 R125 Jan 18 R125 Feb 18 R125 Mar 18 ... R128

Using PIVOT to Flip Data from Wide to Tall

允我心安 提交于 2019-11-28 01:44:30
问题 I have a table that is rather wide that I would like to convert to tall. The data currently resides like this: VEND YEAR I1_DOLS I1_QTY I2_DOLS I2_QTY I3_DOLS I3_QTY ... 1234 2011 101587 508 203345 334 105938 257 1234 2012 257843 587 235883 247 178475 456 1011 2010 584737 432 587274 356 175737 563 1011 2011 517774 356 483858 456 481785 354 I would like to convert this to a table that looks like this: VEND YEAR MONTH DOLS QTY 1234 2011 1 101587 508 1234 2011 2 203345 334 1234 2011 3 105938 257

Hive - Unpivot functionality in hive

馋奶兔 提交于 2019-11-27 09:37:09
I have two table as follows: Table A userid | code | code_name | property_id 0001 | 1 | apple_id | Y1234 0031 | 4 | mango_id | G4567 0008 | 3 | grape_id | H1209 00013 | 2 | peach_id | Z5643 Table 2 apple_id | mango_id | grape_id | peach_id | new_id Y1234 | R1890 | | | N456098 | G4567 | | B3490 | N002345 T3336 | | H1209 | F3467 | N129087 | D7865 | J6543 | Z5643 | N109876 Desired Resultant table userid | new_id 0001 | N456098 0031 | N002345 0008 | N129087 00013 | N109876 Using the code_name in Table A, I would like to find the respective property_id from Table A in Table B. Basically, match on

User defined concatenate

夙愿已清 提交于 2019-11-27 08:28:37
问题 I am trying to expand my annual planning document to give me more information. Currently however I am stuck. My current Sheet is laid out as follows: I need to create a second sheet that concatenates the client name with each column heading there is a "yes" value in, as its own separate line. Example 1 in the new sheet would become: Example 1 - Annuals Example 1 - Xero Fee I had tried a copy and paste Macro, based on a quantity column counting the rows that include text. This gave the desired

SQL Server 2008 : Convert column value to row

别说谁变了你拦得住时间么 提交于 2019-11-27 06:38:46
问题 I have a table in the following format Country_Code | 1960 | 1961 | 1962 | ..... | 2011 ------------------------------------------------ IND | va11 | va12 | va13 | ..... | va1x AUS | va21 | va22 | va23 | ..... | va2x ENG | va31 | va32 | va33 | ..... | va3x I want to convert it into the below format Country_Code | Year | Value --------------------------- IND | 1960 | va11 IND | 1961 | va12 IND | 1962 | va13 . . IND | 2011 | va1x AUS | 1960 | va21 AUS | 1961 | va22 AUS | 1962 | va23 . . AUS |

SQL Server - Include NULL using UNPIVOT

杀马特。学长 韩版系。学妹 提交于 2019-11-27 05:46:40
问题 UNPIVOT will not return NULLs, but I need them in a comparison query. I am trying to avoid using ISNULL the following example (Because in the real sql there are over 100 fields.: Select ID, theValue, column_name From (select ID, ISNULL(CAST([TheColumnToCompare] AS VarChar(1000)), '') as TheColumnToCompare from MyView where The_Date = '04/30/2009' ) MA UNPIVOT (theValue FOR column_name IN ([TheColumnToCompare]) ) AS unpvt Any alternatives? 回答1: It's a real pain. You have to switch them out

unpivot with dynamic columns plus column names

女生的网名这么多〃 提交于 2019-11-27 05:33:13
I'm trying to unpivot a table with a large number of columns in the format of: PID UID col1 col2 col3... The dynamic SQL below will get me almost everything except the name of the column. The goal is to fill in the "ID" field with the name of the column from which the unpivot value originated. -- Build list of cols we want to unpivot (skip PID & UID) declare @cols nvarchar(max) select @cols = coalesce(@cols+N',', N'') + quotename(c.name) from syscolumns c inner join sysobjects o on c.id = o.id and o.xtype = 'u' where o.name = 'MyTable' and c.name not in ('PID', 'UID') order by c.colid declare

Is it possible to have multiple pivots using the same pivot column using SQL Server

廉价感情. 提交于 2019-11-27 03:16:44
问题 I am facing the following challenge. I need to rotate table data twice over the same column. Here's a screenshot of the data. I want to have one row for each Item ID containing both the purchasing value and the selling value for each year. I tried doing this by selecting the "year" column twice, formatting it a bit so each selling year gets prefixed with a "S" and each purchasing year begins with a "P", and using 2 pivots to rotate around the 2 year columns. Here's the SQL query (used in SQL

SQL Unpivot multiple columns Data

≡放荡痞女 提交于 2019-11-27 03:11:30
问题 I am using SQL server 2008 and I am trying to unpivot the data. Here is the SQL code that I am using, CREATE TABLE #pvt1 (VendorID int, Sa int, Emp1 int,Sa1 int,Emp2 int) GO INSERT INTO #pvt1 VALUES (1,2,4,3,9); GO --Unpivot the table. SELECT distinct VendorID,Orders,Orders1 FROM (SELECT VendorID, Emp1, Sa,Emp2,Sa1 FROM #pvt1 ) p UNPIVOT (Orders FOR Emp IN (Emp1,Emp2) )AS unpvt UNPIVOT (Orders1 FOR Emp1 IN (Sa,Sa1) )AS unpvt1; GO And Here is the result of the above code. VendorID Orders