pivot Questions

1

Can we in SQL (preferably Postgresql) mimic the pandas function pivot_table? For example, let's say we have a table with the following 3 columns: Name Day Value John Sunday 6 John Monday 3 John...
Euphonious asked 16/11, 2021 at 17:28

3

I have a crosstab function that I've used successfully many times in the past, but now it's dumping all the data at the end instead of pivoting it into the output table. It can't seem to find Cross...
Cardinalate asked 18/3, 2019 at 21:26

3

Solved

I have a table with stats for universities that looks like this: StatID | UniversityID | StatValue 1 | 1 | 100 2 | 1 | 90 3 | 1 | 80 1 | 2 | 50 2 | 2 | 55 I'd like a query to return something li...
Vice asked 18/2, 2012 at 3:59

5

Solved

I want to pivot a table based on a field which can contain "dynamic" values (not always known beforehand). I can make it work by hard coding the values (which is undesirable): SELECT * FR...
Andie asked 23/7, 2019 at 21:35

5

Solved

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 purchasi...
Nadbus asked 7/3, 2013 at 14:53

3

I have this query that yields a total of 1 million rows similar to the example extract shown bellow SELECT * FROM sales shop date hour row_no amount shop_1 2012-08-14 00:08:00 P01 10 sho...
Purdah asked 21/4, 2017 at 14:4

4

I have a table like this id month col1 col2 col3 col4 101 Jan A B NULL B 102 feb C A G E And then I want to create report like this desc jan feb col1 A C col2 B A col3 0 G...
Untruthful asked 19/12, 2012 at 1:49

4

Solved

I have a dataframe as given: df = {'TYPE' : pd.Series(['Advisory','Advisory1','Advisory2','Advisory3']), 'CNTRY' : pd.Series(['IND','FRN','IND','FRN']), 'VALUE' : pd.Series([1., 2., 3., 4.])} d...
Xanthus asked 13/6, 2017 at 6:6

11

Solved

Official Laravel documentation has this on sync() function: $user->roles()->sync( array( 1, 2, 3 ) ); You may also associate other pivot table values with the given IDs: $user->roles()-&g...
Cristicristian asked 1/12, 2014 at 14:35

2

Solved

I need to do the following transpose in MS SQL from: Day A B --------- Mon 1 2 Tue 3 4 Wed 5 6 Thu 7 8 Fri 9 0 To the following: Value Mon Tue Wed Thu Fri -------------------------- A 1 3 5 ...
Two asked 8/3, 2013 at 15:44

3

Solved

Hello I have a dataset of 3-5 rows per group as the following and I want to put some columns in a longer format and have on column in a wider format. The first dataset below represents the original...
Younker asked 20/2, 2021 at 17:4

4

Here is my input dataset which contains one row and 12 columns/variables: df <- data.frame(q_q10=0,q_q20=0, q_q30=0,q_q40=400, q_q10_low=0,q_q20_low=0,q_q30_low=0,q_q40_low=350, q_q10_up...
Irrelevant asked 18/10, 2023 at 12:54

2

Solved

I'm having a very tough time trying to figure out how to do this with python. I have the following table: NAMES VALUE john_1 1 john_2 2 john_3 3 bro_1 4 bro_2 5 bro_3 6 guy_1 7 guy_2 8 guy_3 9 A...
Christiniachristis asked 10/3, 2016 at 21:3

2

Solved

I have a sample table named antest as shown below to test the crosstab function. create table antest(student text, subject text, result numeric); insert into antest(student, subject, result) value...
Cuirbouilli asked 13/11, 2017 at 20:54

10

Solved

I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName S 1 LastName Smith 1 Date 12/12/2009 2 FirstName Sam 2 MiddleName S 2 LastName Freddrick ...
Berkley asked 27/8, 2009 at 18:58

5

I am using C# winforms to create an application that needs to turn a datatable into a pivot table. I have the pivot table working fine from a SQL end, but creating it from a datatable seems trickie...
Miry asked 2/4, 2012 at 17:43

2

I am trying to transpose rows into columns, grouping by a unique identifier (CASE_ID). I have a table with this structure: CASE_ID AMOUNT TYPE 100 10 A 100 50 B 100 75 A 200 33 B 200 10 C ...
Dornick asked 18/10, 2013 at 18:52

4

Solved

In Python, I have a pandas DataFrame similar to the following: Item | shop1 | shop2 | shop3 | Category ------------------------------------ Shoes| 45 | 50 | 53 | Clothes TV | 200 | 300 | 250 | Tec...
Vtarj asked 2/4, 2017 at 20:3

5

Solved

I have a dataset that looks something like this: I'd like to aggregate all co values on one row, so the final result looks something like: Seems pretty easy, right? Just write a query using c...
Respirator asked 11/5, 2018 at 19:54

6

Solved

Is there a quick way to "unpivot" an Excel matrix/pivot-table (in Excel or elsewhere), without writing macros or other code ? Again, I can write code (C# or VBA or whatever) that does that myselfs...
Fowliang asked 20/8, 2015 at 10:1

3

Solved

I cannot figure out how to do "reverse melt" using Pandas in python. This is my starting data label type value 0 x a 1 1 x b 2 2 x c 3 3 y a 4 4 y b 5 5 y c 6 6 z a 7 7 z b 8 8 z c 9 Th...
Confederate asked 2/3, 2014 at 12:32

9

Solved

I have the following dataframe. df.head(30) struct_id resNum score_type_name score_value 0 4294967297 1 omega 0.064840 1 4294967297 1 fa_dun 2.185618 2 4294967297 1 fa_dun_dev 0.000027 3 429496...
Coolie asked 21/6, 2015 at 1:7

6

Solved

I'd like to get a table which stores students data in long format and the marks they receive for all of their subjects in one query. This is my table structure: Table: markdetails ## studid ## #...
Henhouse asked 6/8, 2009 at 5:5

5

Solved

I am having difficulties writing a Postgres function, as I am not familiar with it. I have multiple tables to import into Postgres with this format: id | 1960 | 1961 | 1962 | 1963 | ... __________...
Ovenbird asked 2/9, 2014 at 14:3

5

Solved

I'm looking for an efficient way to convert rows to columns in SQL server, I heard that PIVOT is not very fast, and I need to deal with lot of records. This is my example: Id Value ColumnName ...
Silber asked 1/4, 2013 at 14:11

© 2022 - 2025 — McMap. All rights reserved.