Questions tagged [crosstab]

A cross tab, also known as a "pivot table", is a method of summarizing data in tabular form. Typically, these have a category column in the left hand side, and multiple summary columns to the right. Each different category will have its own row. Be sure to also include the relevant language tag (python, R, sql-server etc.) on your question.

Resources:

1549 questions
5
votes
2 answers

Sql Server 2008 Cross Tab Query

I usually can figure out any sql queries I need for my applications, but I have recently been stumped by a Cross Tab query I need to create and was wondering if you could help? I have 3 tables Category(catID, catTitle) Equipment(equipID, make,…
tcode
  • 5,055
  • 19
  • 65
  • 124
5
votes
2 answers

Dynamic column alias from another column value in SELECT

I was wondering if there a way, in a SELECT statement on Postgres, to alias a column with the value of another column in the same data set. Given this table: id key value 1 a d 2 a e 3 b f This would be the…
bertonc96
  • 772
  • 2
  • 13
  • 24
5
votes
5 answers

How to create an Access crosstab query with totals for the columns AND the rows?

I want my query result to look like this: Person1 Person2 Person3 Person4 Total Status1 2 4 7 3 16 Status2 0 1 0 3 4 Status3 0 0 0 0 0 Status4…
Joshua Stafford
  • 582
  • 2
  • 7
  • 19
5
votes
2 answers

Group by unique Name and Status with the last Date

I would like to analyze statistics per cars which were repairs and which are new. Data sample is: Name IsItNew ControlDate Car1 True 31/01/2018 Car2 True 28/02/2018 Car1 False 15/03/2018 Car2 True 16/04/2018 Car3 …
Cindy
  • 568
  • 7
  • 20
5
votes
1 answer

function crosstab(unknown, unknown) does not exist but it does

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 Crosstab. I've researched it doing the…
giltdsur
  • 55
  • 1
  • 2
  • 7
5
votes
1 answer

Cross tab on one column where third column is matched

I am trying to do a cross tab based on one column where a third column matches. Take the example data: df = pd.DataFrame({'demographic' : ['A', 'B', 'B', 'A', 'C', 'C'], 'id_match' : ['101', '101', '201', '201', '26', '26'], …
JDraper
  • 349
  • 2
  • 11
5
votes
2 answers

Pyspark dataframe: crosstab or other method to make row label as new columns

I have a pyspark dataframe as follows in the picture: I.e. i have four columns: year, word, count, frequency. The year is from 2000 to 2015. I could like to have some operation on the (pyspark) dataframe so that i get the result in a format as…
XYZ
  • 352
  • 5
  • 19
5
votes
1 answer

PostgreSQL Crosstab: Month rows and Day columns; Error rowid datatype does not match return rowid datatype

I am trying to create a crosstab table that will have rows = months and columns = days (ie 1, 2, 3, 4...31). Month | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ... …
Dys_Lexi_A
  • 343
  • 4
  • 11
5
votes
0 answers

Angular5: window.addEventListener stuck browser tab

My app is having multiple tab support. So I am saving all the data in localStorage. The app is also having socket support and on successful login, I have to authorize socket by emitting an event. Now in one scenario, what if the user has open…
Pinank Lakhani
  • 1,109
  • 2
  • 11
  • 31
5
votes
2 answers

Postgres Crosstab allocating values to wrong columns

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) values ('peter','music',2.0),…
Mike
  • 147
  • 2
  • 16
5
votes
1 answer

How do you create a query which returns dynamic column names in Postgresql?

I have two tables in a reporting database, one for orders, and one for order items. Each order can have multiple order items, along with a quantity for each: Orders +----------+---------+ | order_id | email | +----------+---------+ | 1 |…
Joe
  • 51
  • 1
5
votes
3 answers

Pandas crosstab - How to print rows/columns for values that don't exist in the data sets?

I am a beginner with pandas at best and I couldn't find a solution to this problem anywhere. Let's say I have two variables: variable1, variable2. They can have the following predefined values: variable1 = ['1', '4', '9', '15', '20'] variable2 =…
5
votes
1 answer

Why does this crosstab() query return duplicate keys?

I have following table called sample_events: Column | Type --------+----- title | text date | date with values: title | date -------+------------ ev1 | 2017-01-01 ev2 | 2017-01-03 ev3 | 2017-01-02 ev4 | 2017-12-10 ev5 |…
AG13
  • 63
  • 4
5
votes
2 answers

Crystal Reports crosstab

I am new to crystal reports so this might be novice to you. I have created a cross tab with row grand total to the right. How can I add an extra column to display Average of the rows. I am using Crystal reports 2008 Here is a rough example of the…
user455580
  • 329
  • 1
  • 4
  • 18
5
votes
3 answers

Create a two-mode frequency matrix in R

I have a data frame, which looks something like this: CASENO Var1 Var2 Resp1 Resp2 1 1 0 1 1 2 0 0 0 0 3 1 1 1 1 4 1 1 0 1 5 1 0 …
jj987246
  • 105
  • 6