pivot

Multi column data transformation

一个人想着一个人 提交于 2020-01-02 01:37:09
问题 I am receiving data from a data source which I need to pivot before I can send the information to UI for display. I am new to concept of pivoting & I am not sure how to go about it. There are two parts to the problem: forming the header Pivoting the data to match the header Things to keep in mind: I have certain columns which I do not want to pivot. I call them static columns. I need to pivot certain columns to form multi level header info. I call them dynamic columns Some columns needs to be

Split rows into 12 columns

假如想象 提交于 2020-01-01 19:33:09
问题 I have a table with, say, 1000 rows. One of those columns is URL. So, select URL from table. However I want to display 12 URLs per row. The reason is that we are publishing work for people to do online and they will review 12 websites at a time. So in this case we would have about 90 rows being output, each having 12 columns (except the last row which will be short a few). Is there a straightforward way to do this? Is this a case for pivot or some other function? 回答1: Simple example with

Oracle PIVOT, twice?

倖福魔咒の 提交于 2020-01-01 18:59:44
问题 I have been trying to move away from using DECODE to pivot rows in Oracle 11g, where there is a handy PIVOT function. But I may have found a limitation: I'm trying to return 2 columns for each value in the base table. Something like: SELECT somethingId, splitId1, splitName1, splitId2, splitName2 FROM (SELECT somethingId, splitId FROM SOMETHING JOIN SPLIT ON ... ) PIVOT ( MAX(splitId) FOR displayOrder IN (1 AS splitId1, 2 AS splitId2), MAX(splitName) FOR displayOrder IN (1 AS splitName1, 2 as

BigQuery Pivot Data Rows Columns

本小妞迷上赌 提交于 2020-01-01 10:41:52
问题 Im currently processing data in BigQuery then export into Excel to do the final Pivot table and was hoping to be able to create the same with the PIVOT option in BigQuery. My Data set in big query looks like Transaction_Month || ConsumerId || CUST_createdMonth 01/01/2015 || 1 || 01/01/2015 01/01/2015 || 1 || 01/01/2015 01/02/2015 || 1 || 01/01/2015 01/01/2015 || 2 || 01/01/2015 01/02/2015 || 3 || 01/02/2015 01/02/2015 || 4 || 01/02/2015 01/02/2015 || 5 || 01/02/2015 01/03/2015 || 5 || 01/02

BigQuery Pivot Data Rows Columns

橙三吉。 提交于 2020-01-01 10:41:06
问题 Im currently processing data in BigQuery then export into Excel to do the final Pivot table and was hoping to be able to create the same with the PIVOT option in BigQuery. My Data set in big query looks like Transaction_Month || ConsumerId || CUST_createdMonth 01/01/2015 || 1 || 01/01/2015 01/01/2015 || 1 || 01/01/2015 01/02/2015 || 1 || 01/01/2015 01/01/2015 || 2 || 01/01/2015 01/02/2015 || 3 || 01/02/2015 01/02/2015 || 4 || 01/02/2015 01/02/2015 || 5 || 01/02/2015 01/03/2015 || 5 || 01/02

Using PIVOT and JOIN together

走远了吗. 提交于 2020-01-01 00:46:17
问题 Consider This Query: SELECT [Order Details].OrderID, c.CategoryName, COUNT(c.CategoryID) FROM [Order Details] INNER JOIN Products p ON p.ProductID = [Order Details].ProductID INNER JOIN Categories c ON c.CategoryID = p.CategoryID GROUP BY [Order Details].OrderID, c.CategoryName ORDER BY [Order Details].OrderID this query returns this such result (Usnig Northwind Database): I want to use Pivot with Join to get such this result: OrderID Condiments Produce Seafood Condiments Grains/Cereals ... -

Pivot in SQL 2008 R2

只愿长相守 提交于 2019-12-31 07:41:44
问题 I have table like this; Date PlacementName campaignID Impressions Clicks TotalConversions Activity 01/01/2014 USA 100 5000 500 50 Mobile Book 01/02/2014 U.K 101 7000 250 30 Mobile Book 01/01/2014 USA 100 9000 800 40 Mobile TV 01/02/2014 U.K 101 6000 300 10 Mobile TV I want to pivot table for 15-20 Activity from the real table because this is just example table. I want my table look like below; Date PlacementName CampaignID Impressions Clicks Mobile Book Mobile TV 01/01/2014 USA 100 5000 500

Pivot in SQL 2008 R2

馋奶兔 提交于 2019-12-31 07:41:06
问题 I have table like this; Date PlacementName campaignID Impressions Clicks TotalConversions Activity 01/01/2014 USA 100 5000 500 50 Mobile Book 01/02/2014 U.K 101 7000 250 30 Mobile Book 01/01/2014 USA 100 9000 800 40 Mobile TV 01/02/2014 U.K 101 6000 300 10 Mobile TV I want to pivot table for 15-20 Activity from the real table because this is just example table. I want my table look like below; Date PlacementName CampaignID Impressions Clicks Mobile Book Mobile TV 01/01/2014 USA 100 5000 500

PostgreSQL query with generated columns

做~自己de王妃 提交于 2019-12-31 05:27:10
问题 I have a schema as show like the below, and I want to run a query where I get a column in the output for every row of the points table. So for each usage row I want to multiply the amount of the usage times the amount for the referenced points_id , and then sum that up and group by person. So for the example data I'd want output that looked like this: Name | foo | bar | baz -------|------|------|------ Scott | 10.0 | 24.0 | 0.0 Sam | 0.0 | 0.0 | 46.2 Here's the schema/data: CREATE TABLE

Pandas: subtract one column from another in a pivot table

梦想的初衷 提交于 2019-12-31 04:53:09
问题 I would like to subtract one columns from another in a pivot table. 'diff' shoud be the difference between 2017 and 2016 raw_data = {'year': [2016,2016,2017,2017], 'area': ['A','B','A','B'], 'age': [10,12,50,52]} df1 = pd.DataFrame(raw_data, columns = ['year','area','age']) table=pd.pivot_table(df1,index=['area'],columns=['year'],values['age'],aggfunc='mean') table['diff']=table['2017']-table['2016'] 回答1: You need remove [] in pivot_table for dont create MultiIndex in columns: table=pd.pivot