Questions tagged [pivot]

The PIVOT syntax converts row data into columnar data, and vice versa for the UNPIVOT syntax. The syntax is non-standard, and not all databases support the PIVOT syntax, but the functionality can be implemented, often using decision logic (CASE expressions, etc) and aggregate functions.

Filter by
Sorted by
Tagged with
-6 votes
1 answer
35 views

Oracle sql aggregate results from a query [duplicate]

I have this table: I don't know how I can get these results, based on the occupation and age of employees: I'm inexperienced at this. In excel I use a pivot table. But how can I do it with SQL?
Dorito's user avatar
  • 231
-1 votes
1 answer
22 views

Pivot without aggregation

How can I pivot the output so each id will refelct a primary and secondary min_score. current output is long and I need wide. Having to use rate to create a classification and the subsequent group by ...
Rich's user avatar
  • 27
-3 votes
0 answers
29 views

How to implement dynamic pivot in SQL Server? [duplicate]

I wanted to do sum of working hours of each resource in particular group per month and transpose the Date column values (01-01-2023) as Month-Year (Jan-23) column. Input Expected Output I tried this ...
VC6135's user avatar
  • 1
0 votes
1 answer
43 views

Oracle EXECUTE IMMEDIATE does not display output

I have written below pivot query but it is not showing any output rows. It just shows PL/SQL procedure successfully completed. DECLARE expression CLOB; BEGIN SELECT LISTAGG('''' || MONTH || ''' ...
Sam's user avatar
  • 43
1 vote
1 answer
24 views

Google Sheets Pivot Table

Is there a way to add a comment column to the right of a pivot table, and ensure that the comments added also move correctly when the pivot table is refreshed? For example, If I have a pivot table ...
Rosanna Caruso's user avatar
1 vote
0 answers
14 views

Vue3 component does not call onMounted hook

Project is Vue3 + Typescript + composition api. I have pretty simple component which contains onMounted() hook which should set up some properties after data change. Parent component make API request ...
Čamo's user avatar
  • 3,963
-1 votes
0 answers
88 views
+50

How to merge separate lapply and enable pivot_long column reading

I am performing the same operation through separated list of dataset x1 = c(1, 2) x2 = c(3, 4) x3 = c(5, 6) data1 = flatten(lapply(seq(1:3), function(y) lapply(seq(1:2), function(...
12666727b9's user avatar
  • 1,043
1 vote
0 answers
18 views

In BigQuery, how to clusterize Stackoverflow tags?

I'm trying to clusterize the Stackoverflow tags from the BigQuery public dataset. According to one of my data specialists colleagues, the standard procedure is to link each tag to the "nearest&...
Riduidel's user avatar
  • 22.1k
0 votes
2 answers
22 views

Summary of representative monthly sales in Oracle

The goal of the request is to obtain a table of the monthly sales of every representative for the last 3 years. It should looks like this: SELLER_ID SELLER MONTH 2023 2022 2021 0001 JohnSmith ...
MensSana's user avatar
  • 521
-1 votes
1 answer
30 views

how to pivot with two columns in sql

I meet a stuck when trying to working with Sql pivot I am not a master sql and i trying to convert my table to pivot for the report I am so appriciate for any helps I can pivot one column plandate/...
Tuan La's user avatar
-1 votes
1 answer
62 views

MariaDB query row to column with unique filter

I am trying to convert some rows to columns in a single table and can't get it work. :( Here is my simple MariaDB table called runningtimes: So I have tried various methods including pivot or ...
OpperSnokker's user avatar
0 votes
1 answer
29 views

Using pivot on multiple columns

I have the following sample data in an Oracle table (tab1) and I am trying to convert rows to columns. With pivot table I am able to have person_id like intended but in columns I can only achieve to ...
ORA20001's user avatar
0 votes
1 answer
29 views

dbt pivot multiple columns

I have the following table in my_model.sql: NAMES COUNTRY DATE AGE mario uk 2021 38 robert uk 2022 18 frank usa 2011 55 julia usa 1999 80 I need to pivot the table and have the final result as: ...
l217's user avatar
  • 83
-1 votes
0 answers
17 views

How to pivot hive table, using hql

I want to know that how to pivot hive table, using hql. below example is simple example. I have too many keys, so can not use case when phrase. I have a hive table like this. id kv 1 [{"key&...
fleamon's user avatar
0 votes
2 answers
33 views

how to change vertical query result to horizontal in oracle [duplicate]

this is the result from a complicated query with many joins : enter image description here What I want is : enter image description here How do I accomplish this ? tried to use pivot, but I am not ...
Eddie's user avatar
  • 9
1 vote
3 answers
52 views

Pandas: how do I use the columns as the indices and then have repeats in the former indices become repeats in the new indices?

Basically I'm trying to convert this, dft = pd.DataFrame({1: [0.1,0.4,0.2,0.5],2:[0.4,0.5,0.3,0.4],3:[0.2,0.4,0.6,0.7]}, index=['t1', 't1','t2','t2']) dft.index.name = "tt" dft.columns.name='...
user14094230's user avatar
-2 votes
0 answers
41 views

Transpose column python pandas

I have a excel spreadsheet where all of the values are transposed in a single column but I want to transpose them to multiple columns with the question response to match the column accordingly. Python ...
jones0207's user avatar
0 votes
0 answers
22 views

Google Sheets - Pivot table is breaking every time the data sheet powering the pivot is updated

I have a google-sheet with a protected (padlocked) raw-data sheet which is being updated by a third party. I have a pivot table based on this data sheet which is breaking every day when the data sheet ...
Ben's user avatar
  • 1
-1 votes
1 answer
34 views

pandas group by with multiple agg not working on multiple columns

file table need to be I have a dataset where I need to report same exact image. Sub-activity is int project is a category " 3 project only" status is block, complete, on going is that doable ...
Sultan's user avatar
  • 5
0 votes
1 answer
13 views

Laravel 8 syncWithPivotValues() do not work as expected

I have three tables: audiences, companies and audience_company. Pivot table audience_company contains columns audience_id, company_id and type. So I differentiate data according type column. There is ...
Čamo's user avatar
  • 3,963
0 votes
0 answers
19 views

Change Pivot table Cache code not working

I'm trying to change the pivot cache to the actual pivot table itself. I've filtered the data in a way I like and cant let other people see the unfiltered data and as such I'm using the filtered table ...
Nrhoodie's user avatar
-2 votes
0 answers
9 views

How can I re-order my dataframe based on a character column in R?

I have a data frame with 3 columns (Sample, MW, Area) and 63 Rows of Samples (R1-R21) but not in order. like: R21,R21,R3,R3,R1,R1,.... I need to sort my sample column from R1-R21, but I can't find the ...
elnaz rahbar's user avatar
1 vote
2 answers
28 views

Match when pivoting longer

I have the following dataset and I want to pivot part_c_name_1 and part_c_name_2 by one side and then, harvest_1 and harvest_2. When I try to do this with pivot_longer it does not understand that ...
Paula's user avatar
  • 559
0 votes
0 answers
11 views

Pivot a dataframe with two columns (where a column has duplicate values) [duplicate]

I am trying to pivot my current two column dataframe which currently looks like this: enter image description here I want to pivot this and the final dataframe should look like this: enter image ...
Aniket Kumar's user avatar
0 votes
0 answers
22 views

How to apply PIVOT on two columns and translate into one row? [duplicate]

I have two columns in the source table and I am trying to apply pivot to translate into one row. The Name column will be dynamic and I would not know upfront the number of Names and which Names to ...
Jyina's user avatar
  • 2,538
0 votes
2 answers
42 views

Spilt items in a row to columns through pandas

I need to splits items in a row to columns on the occurence of '^' character. This needs to done through pandas without a loop preferably I have 0 A^ 3 206-1C 4 502-2B 5 506-0.5C 6 604-1B 7 ...
Vedant Ghavate's user avatar
-2 votes
1 answer
42 views

Change the result of SQL query by PIVOT

I am going to change the model of result in SQL query. Imagine the query below: SELECT es.LatinName, es.CreatedOn FROM Salex.ExportFile ef INNER JOIN Salex.ExportFileStep efs ON efs....
Sasan's user avatar
  • 612
1 vote
3 answers
54 views

Combine two rows into one based on identifier

My dataset looks like this: LBID ADDRESS FI LI 101 7283 JOHN SMITH 101 7283 JANE JONES Since John and Jane have the same LBID and the same Address, I want the output to look like this: LBID ...
Larinx's user avatar
  • 23
0 votes
0 answers
14 views

Account Name error on multiple Pivot Tables on different workbooks

I have 4 multiples workbooks and all workbooks contains multiple pivots with Common fields Account Name and Year. I've written a code to change all Pivot at once on Account Name & Year but ...
Lal Sahab's user avatar
0 votes
1 answer
28 views

Tidy Pivot a Table based on 3 columns in R [duplicate]

Current data: user_ID age_v1 age_v2 age_v3 gender visit score 1 63 65 67 M v1 8 1 63 65 67 M v2 4 1 63 65 67 M v3 ...
pdw5's user avatar
  • 33
0 votes
3 answers
48 views

Transform Table Format From Vertical to Horizontal

I found a similar post to what I want to achieve but the other way around https://superuser.com/questions/683413/transform-horizontal-table-layout-to-vertical-table I want to transform this City Name ...
Kerovin's user avatar
0 votes
1 answer
21 views

How to make pivot_longer plot wotk if I use datawizard::standardize to make z-score instead of scale in R

I am compiling a report and for some statistical analyses, I am using the z-scores for certain columns in my dataframe. This required me to use the scale function, but recently, I have been tessting ...
anonymous's user avatar
1 vote
2 answers
45 views

Postgres PIVOT table on aggregated count

I am trying to create a pivot table in Postgres from the following table named product_info: CREATE TABLE product_info ( ID varchar(10), date VARCHAR(20) NOT NULL, product VARCHAR(20) NOT ...
shaik faiz's user avatar
-1 votes
0 answers
18 views

How to Pivot date values in a column? [duplicate]

I have the following SQL Query: SELECT account_no, period, (total_revenue - total_expense + ach - Net_Income) AS Calculation FROM table The above SQL query outputs the below (for 1 ID): Account_no ...
Dryko's user avatar
  • 11
0 votes
1 answer
21 views

Combining two dataframes based on two variables when one variable is a single column format in DF1 and across several columns in DF2

This is my first post so hopefully I have included all the necessary information. I don't think it replicates previously answered questions. Eventually I am trying to combine numerous datasets ...
Sammy_beep_beep's user avatar
0 votes
1 answer
21 views

Dataframe Pivot Index contains duplicate entries

I am currently using dataframe pivot function as below, but I am getting below error: df = pd.DataFrame({'team': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'], 'Serialno': [1,2,2,1,1,2,2,...
PythonDeveloper's user avatar
1 vote
1 answer
35 views

Python - convert each row in columns in a specific way [duplicate]

I have some data like shown below. Group Item1 Value1 Item2 Value2 ……so on Val10 A apple 2 pears -4 B orange -5 banana 3 C grapes 6 apple ...
sam's user avatar
  • 87
0 votes
1 answer
44 views

RETURN cannot have a parameter in function returning set while returning from function

I have following code but this is throwing error: RETURN cannot have a parameter in function returning set Any idea on how I can fix it and why I am getting this error? DROP FUNCTION IF EXISTS ...
Alwaysblue's user avatar
-1 votes
1 answer
38 views

Need to pivot pandas dataframe

I downloaded a csv from the world bank website that has stats for Australia going back to 1960(https://data.worldbank.org/country/australia) . I have read the csv in to a pandas dataframe but after ...
adamc's user avatar
  • 1
0 votes
1 answer
31 views

How do I compress rows in each column to get rid of the blank cells in python?

This is the original Ter119high_df new_columns = Ter119high_df['Specimen'].unique() new_df = pd.DataFrame(columns=new_columns) print(new_df) # Fill the new DataFrame with percentage values for index, ...
Monica B's user avatar
0 votes
1 answer
37 views

Add Multiple Columns to a Pivot Table with pandas + python [duplicate]

I have a table with a list of products, their balances and prices, and I need to make a pivot table out of it. I have table like this: Name Model Amount Price audi q5 1 18000 audi q7 5 22000 I'm ...
Alik Muradyan's user avatar
1 vote
1 answer
19 views

How to display Dynamic pivot table using php mysql

I have this dynamic pivot table code that successfully generate my pivot table in sql. But am finding it very difficult to display the dynamic pivot table on my webpage using php. Please i need your ...
Daniel Agboje's user avatar
0 votes
4 answers
75 views

SQL how to eliminate or consolidate the result in less rows from multiple rows in my fact table

How to eliminate or consolidate the result in less rows from multiple rows in the aggregation table? Current situation is the first table#1 with 6 rows: cntrc_key re_key aup_key insr_key drvr_key ...
LV6001's user avatar
  • 17
0 votes
1 answer
29 views

Pandas pivot to create table but columns have multiple values [duplicate]

I am working with a text file containing a table I need to extract specific columns and create a single row (making Sample ID index, and columns should be Gene ID with the values extracted from ...
natural_d's user avatar
0 votes
0 answers
19 views

Excel 2016: How to create a pivot table and line chart where I can select each month using a slicer

I have a very large spreadsheet with a lot of financial data broken down into type of expense in each month of the FY. I'm trying to create multiple pivot tables and charts with a single slicer named &...
Steve's user avatar
  • 69
1 vote
1 answer
36 views

Interaction Effects of Students in R

I am working with a dataset df1 in R. It has two columns: Date and Student_ID. I first want to find out the number of pairs of students who have appeared together in a certain date. Suppose these ...
thedumbkid's user avatar
0 votes
1 answer
27 views

SQL Pivot/Unpivot similar column names

drop table if exists tbl go create table tbl( refId int, refNm varchar(10), prodID_0 int, prodNm_0 varchar(10), prodDesc_0 VARCHAR(10), prodID_1 int, prodNm_1 varchar(10), prodDesc_1 VARCHAR(10), ...
Al Jaffa's user avatar
2 votes
0 answers
71 views

How to set names_sep and/or names_pattern in pivot_longer function

I am trying to use pivot_longer in one go By omitting the names_sep argument it turns me back the error reported below: mtcars %>% pivot_longer(c(1:3, 6:7), names_to = c('name1', 'name2'), ...
12666727b9's user avatar
  • 1,043
0 votes
1 answer
26 views

How to solve error related to name repair startegy with double pivot_longer

I have been trying to convert separately columns as long format, by using the following code: mtcars %>% pivot_longer(1:3, values_to = 'values') %>% pivot_longer(6:7, values_to = 'values1')...
12666727b9's user avatar
  • 1,043
2 votes
4 answers
53 views

Postgres columns to rows

I have a PostgreSQL table which gives me the following output: country metric_code male female pensioners teenagers us metric_1 10 14 22 30 us metric_2 105 142 222 309 uk metric_1 15 13 9 21 uk ...
Maximusrs's user avatar

1
2 3 4 5
228