unpivot

Hive - Unpivot functionality in hive

和自甴很熟 提交于 2019-11-26 14:47:13
问题 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

How to simulate UNPIVOT in Access?

女生的网名这么多〃 提交于 2019-11-26 13:49:09
UNPIVOT is available in MS SQL-Server 2005, but AFAIK not in MS Access 2010. How can it be implemented with on-board means? For example, I have a table ID | A | B | C | Key 1 | Key 2 | Key 3 --------------------------------------- 1 | x | y | z | 3 | 199 | 452 2 | x | y | z | 57 | 234 | 452 and want to have a table like ID | A | B | C | Key -------------------- 1 | x | y | z | 3 2 | x | y | z | 57 1 | x | y | z | 199 2 | x | y | z | 234 2 | x | y | z | 452 Key 452 is a special case. Currently I do the rotation in OLEDB/ATL C++. Although it is fast enough I'm still curious. What is the most

SQL Server Pivot Table with multiple column aggregates

陌路散爱 提交于 2019-11-26 11:48:00
I've got a table: create table mytransactions(country varchar(30), totalcount int, numericmonth int, chardate char(20), totalamount money) The table has these records: insert into mytransactions(country, totalcount, numericmonth, chardate, totalamount) values('Australia', 36, 7, 'Jul-12', 699.96) Go insert into mytransactions(country, totalcount, numericmonth, chardate, totalamount) values('Australia', 44, 8, 'Aug-12', 1368.71) Go insert into mytransactions(country, totalcount, numericmonth, chardate, totalamount) values('Australia', 52, 9, 'Sep-12', 1161.33) Go insert into mytransactions

unpivot with dynamic columns plus column names

吃可爱长大的小学妹 提交于 2019-11-26 11:37:20
问题 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

Transposing Dynamic Columns to Rows

谁说我不能喝 提交于 2019-11-26 11:24:23
I'd like to know how to unpivot Table_1 into Expected_Result_Table : Table1 ----------------------------------------- Id abc brt ccc ddq eee fff gga hxx ----------------------------------------- 12345 0 1 0 5 0 2 0 0 21321 0 0 0 0 0 0 0 0 33333 2 0 0 0 0 0 0 0 41414 0 0 0 0 5 0 0 1 55001 0 0 0 0 0 0 0 2 60000 0 0 0 0 0 0 0 0 77777 9 0 3 0 0 0 0 0 Expected_Result_Table --------------------- Id Word Qty>0 --------------------- 12345 brt 1 12345 ddq 5 12345 fff 2 33333 abc 2 41414 eee 5 41414 hxx 1 55001 hxx 2 77777 abc 9 77777 ccc 3 So, How to transpose columns in Table_1 resulting in Expected

unpivot and PostgreSQL

旧城冷巷雨未停 提交于 2019-11-26 10:27:34
Is there a unpivot equivalent function in PostgreSQL? Create an example table: CREATE TEMP TABLE foo (id int, a text, b text, c text); INSERT INTO foo VALUES (1, 'ant', 'cat', 'chimp'), (2, 'grape', 'mint', 'basil'); You can 'unpivot' or 'uncrosstab' using UNION ALL: SELECT id, 'a' AS colname, a AS thing FROM foo UNION ALL SELECT id, 'b' AS colname, b AS thing FROM foo UNION ALL SELECT id, 'c' AS colname, c AS thing FROM foo ORDER BY id; This runs 3 different subqueries on foo , one for each column we want to unpivot, and returns, in one table, every record from each of the subqueries. But

How do you create a “reverse pivot” in Google Sheets?

99封情书 提交于 2019-11-26 09:36:56
问题 I am trying to produce a \"reverse pivot\" function. I have searched long and hard for such a function, but cannot find one that is already out there. I have a summary table with anywhere up to 20 columns and hundreds of rows, however I would like to convert it into a flat list so I can import to a database (or even use the flat data to create more pivot tables from!) So, I have data in this format: | Customer 1 | Customer 2 | Customer 3 ----------+------------+------------+-----------

How to simulate UNPIVOT in Access?

爷,独闯天下 提交于 2019-11-26 03:44:10
问题 UNPIVOT is available in MS SQL-Server 2005, but AFAIK not in MS Access 2010. How can it be implemented with on-board means? For example, I have a table ID | A | B | C | Key 1 | Key 2 | Key 3 --------------------------------------- 1 | x | y | z | 3 | 199 | 452 2 | x | y | z | 57 | 234 | 452 and want to have a table like ID | A | B | C | Key -------------------- 1 | x | y | z | 3 2 | x | y | z | 57 1 | x | y | z | 199 2 | x | y | z | 234 2 | x | y | z | 452 Key 452 is a special case. Currently

SQL Server Pivot Table with multiple column aggregates

孤人 提交于 2019-11-26 03:33:56
问题 I\'ve got a table: create table mytransactions(country varchar(30), totalcount int, numericmonth int, chardate char(20), totalamount money) The table has these records: insert into mytransactions(country, totalcount, numericmonth, chardate, totalamount) values(\'Australia\', 36, 7, \'Jul-12\', 699.96) Go insert into mytransactions(country, totalcount, numericmonth, chardate, totalamount) values(\'Australia\', 44, 8, \'Aug-12\', 1368.71) Go insert into mytransactions(country, totalcount,

Transposing Dynamic Columns to Rows

守給你的承諾、 提交于 2019-11-26 03:26:57
问题 I\'d like to know how to unpivot Table_1 into Expected_Result_Table : Table1 ----------------------------------------- Id abc brt ccc ddq eee fff gga hxx ----------------------------------------- 12345 0 1 0 5 0 2 0 0 21321 0 0 0 0 0 0 0 0 33333 2 0 0 0 0 0 0 0 41414 0 0 0 0 5 0 0 1 55001 0 0 0 0 0 0 0 2 60000 0 0 0 0 0 0 0 0 77777 9 0 3 0 0 0 0 0 Expected_Result_Table --------------------- Id Word Qty>0 --------------------- 12345 brt 1 12345 ddq 5 12345 fff 2 33333 abc 2 41414 eee 5 41414