unpivot

Convert single column to single row

风格不统一 提交于 2019-12-11 04:45:50
问题 I have a table with a single column like so: +-------------+ |(Column Name)| +-------------+ |Data1 | +-------------+ |Data2 | +-------------+ |Data3 | +-------------+ |Data4 | +-------------+ |Data5 | +-------------+ What I want to do seems very simple, but I am not able to find any examples of it anywhere. All I want is to convert the above column into a single row like so: +-------+-------+-------+-------+-------+ | (Col1)| (Col2)| (Col3)| (Col4)| (Col5)| +-------+-------+-------+-------+-

How to Unpivot with dynamic columns Oracle

醉酒当歌 提交于 2019-12-11 04:27:30
问题 I need to unpiviot a table that I don't have control over the columns, so i need to dynamically get the column names: This is what I have CREATE TABLE test ( PK VARCHAR2(255 CHAR), COL1 VARCHAR2(255 CHAR), COL2 VARCHAR2(255 CHAR), COL3 VARCHAR2(255 CHAR), COL4 VARCHAR2(255 CHAR), COL5 VARCHAR2(255 CHAR), COL6 NUMBER, ) declare sql_stmt clob; pivot_clause clob; begin select listagg('''' || column_name || ''' as "' || column_name || '"', ',') within group (order by column_name) into pivot

Rearrange certain columns and rows

别说谁变了你拦得住时间么 提交于 2019-12-11 03:49:31
问题 I have an Excel spreadsheet formatted like this: What I have been trying to do is format it to look like this: So it's kind of transposed I guess (not sure how to call it). I've spent the last hour and a half trying to do it in VBA with no success. This is just a sample of how it is formatted, in reality there's about 50,000 of these, so I need to do it using VBA or something of the sort. Would someone be able to help me out with how to do this? 回答1: With Excel 2007 you don’t necessarily need

Oracle UNPIVOT and SYSDATE giving weird results

♀尐吖头ヾ 提交于 2019-12-11 02:44:34
问题 I am trying to transpose columns to rows using query similar to the following... WITH query AS ( SELECT SYSDATE AS SomeDate, 'One' AS One, 'Two' AS Two, 'Three' AS Three, 'Four' AS Four, 'Five' AS Five FROM dual ), up_query AS ( SELECT * FROM query UNPIVOT ( NUM FOR DUMMY IN ( One AS 'One', Two AS 'Two', Three AS 'Three', Four AS 'Four', Five AS 'Five' ) ) ) SELECT SYSDATE, b.* FROM up_query b; I was expecting SomeDate to reflect SYSDATE for the resulting rows... But this is the result I am

Pivot a fixed multiple column table in sql server

喜欢而已 提交于 2019-12-11 02:02:58
问题 I have a table which I need to pivot for reporting services: DateCreated Rands Units Average Price Success % Unique Users ------------------------------------------------------------------------- 2013-08-26 0 0 0 0 0 2013-08-27 0 0 0 0 0 2013-08-28 10 2 5 100 1 2013-08-29 12 1 12 100 1 2013-08-30 71 9 8 100 1 2013-08-31 0 0 0 0 0 2013-09-01 0 0 0 0 0 In other words I need to have Rands, Units, Average Price etc at rows and the dates as columns. I have read various examples but I just can't

Pandas 'partial melt' or 'group melt'

隐身守侯 提交于 2019-12-10 19:23:18
问题 I have a DataFrame like this >>> df = pd.DataFrame([[1,1,2,3,4,5,6],[2,7,8,9,10,11,12]], columns=['id', 'ax','ay','az','bx','by','bz']) >>> df id ax ay az bx by bz 0 1 1 2 3 4 5 6 1 2 7 8 9 10 11 12 and I want to transform it into something like this id name x y z 0 1 a 1 2 3 1 2 a 7 8 9 2 1 b 4 5 6 3 2 b 10 11 12 This is an unpivot / melt problem, but I don't know of any way to melt by keeping these groups intact. I know I can create projections across the original dataframe and then concat

Unpivot Multiple Columns in MySQL

ぃ、小莉子 提交于 2019-12-10 19:11:56
问题 I've got some non-normalized data that I'm trying to unpivot the columns on, I'm hoping you all can help me figure out the best way to do this. I've done this using multiple union statements, but what I'm hoping to do is create a dynamic query that can do this over and over as more columns are added to the table. My data looks something like this: (Numerical columns go all the way through 50) | Code | Desc | Code_0 | Desc_0| Period| 1 | 2 | 3 | 4 | |-------|-------|--------|-------|-------|--

SQL Query to Transpose Column Counts to Row Counts

本小妞迷上赌 提交于 2019-12-08 14:16:01
问题 I have a table that looks like the following which shows the count of types. I need to and have been trying to display data as 1 column and 7 rows instead though... without success. __________________________________________________________________________ | col types | win2k | winxp | win2k3 | vista | win7 | win8 | win8.1 | -------------------------------------------------------------------------- | count of types | 2365 | 65655 | 422445 | 4822 | 482 | 2331 | 485323 | -----------------------

Create a row for each cell that has data from multiple columns

a 夏天 提交于 2019-12-08 05:55:33
问题 I'm dealing with data that has been generated from a survey that has a unique respondant ID as the first column and then has multiple columns relating to the choices of country that the respondent was looking at in relation to finding employees. So my table looks something like: RespondentID Andorra Austria Belgium Cyprus Denmark Finland France 2546078180 Andorra NULL NULL Cyprus NULL NULL NULL 2546077668 NULL NULL Belgium NULL NULL NULL NULL 2546077120 NULL NULL NULL NULL Denmark Finland

Rotate/pivot 1000 columns to rows

随声附和 提交于 2019-12-08 02:41:34
问题 I inherited a DB from which I need to extract data in columns that is currently arranged in rows. The query to retrieve the data is: select distinct LIMSNo, p250.*, p500.*, p750.*, p1000.* from results as r inner join Points250 as p250 on r.resultsid = p250.resultsid and p250.channel = 1 inner join Points500 as p500 on r.resultsid = p500.resultsid and p500.channel = 1 inner join Points750 as p750 on r.resultsid = p750.resultsid and p750.channel = 1 inner join Points1000 as p1000 on r