crosstab

PostgreSQL crosstab/pivot problems

旧时模样 提交于 2019-12-21 21:39:42
问题 I have a prefs table, and here are the relevant columns: mydb=> SELECT pref_id, pref_name, pref_value FROM prefs; pref_id | pref_name | pref_value ---------+--------------+---------------- 1 | PagerNumber | 2125551234 2 | PagerCarrier | @att.com 3 | PagerCarrier | @something.com I want to produce something like this: section | pager_number | pager_carrier ---------+----------------+--------------- 1 | 2125551234 | 2 | | @att.com 3 | | @something.com So I used crosstab, following this example

Using Linq to create crosstab results [duplicate]

一世执手 提交于 2019-12-21 08:56:22
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Is it possible to Pivot data using LINQ? I'm wondering if its at all possible to create crosstab style results with Linq. I have some data that looks like the following: var list = new[] { new {GroupId = 1, Country = "UK", Value = 10}, new {GroupId = 1, Country = "FR", Value = 12}, new {GroupId = 1, Country = "US", Value = 18}, new {GroupId = 2, Country = "UK", Value = 54}, new {GroupId = 2, Country = "FR",

Fastest way to cross-tabulate two massive logical vectors in R

让人想犯罪 __ 提交于 2019-12-20 09:58:33
问题 For two logical vectors, x and y , of length > 1E8, what is the fastest way to calculate the 2x2 cross tabulations? I suspect the answer is to write it in C/C++, but I wonder if there is something in R that is already quite smart about this problem, as it's not uncommon. Example code, for 300M entries (feel free to let N = 1E8 if 3E8 is too big; I chose a total size just under 2.5GB (2.4GB). I targeted a density of 0.02, just to make it more interesting (one could use a sparse vector, if that

Linq: How to transform rows to columns with a count (Crosstab data)?

只愿长相守 提交于 2019-12-20 02:38:24
问题 I think I need a way to perform a pivot or crosstab using C# and Linq with an indeterminate number of columns. However, I will add some beginning detail to see where it goes. < Beginning detail > Imagine a table that has two fields: string EventName; Datetime WhenItHappend; We want to generate a report like the example below where we group by the EventName, then have a series of columns that calculate some date and time frame count. The difficulty is obviously a variable number of columns.

Invalid count and sum in cross tab query using PostgreSQL

为君一笑 提交于 2019-12-19 09:43:02
问题 I am using PostgreSQL 9.3 version database. I have a situation where I want to count the number of products sales and sum the amount of product and also want to show the cities in a column where the product have sale. Example Setup create table products ( name varchar(20), price integer, city varchar(20) ); insert into products values ('P1',1200,'London'), ('P1',100,'Melborun'), ('P1',1400,'Moscow'), ('P2',1560,'Munich'), ('P2',2300,'Shunghai'), ('P2',3000,'Dubai'); Crosstab query : select *

Pivot / crosstab with more than one value column

♀尐吖头ヾ 提交于 2019-12-19 07:52:45
问题 I have a view that produces the following resultset: CREATE TABLE foo AS SELECT client_id, asset_type, current_value, future_value FROM ( VALUES ( 1, 0, 10 , 20 ), ( 1, 1, 5 , 10 ), ( 1, 2, 7 , 15 ), ( 2, 1, 0 , 2 ), ( 2, 2, 150, 300 ) ) AS t(client_id, asset_type, current_value, future_value); And I need to transform it into this: client_id a0_cur_val a0_fut_val a1_cur_val a1_fut_val ... 1 10 20 5 10 2 NULL NULL 0 2 I know how to do this if I use just the current_value column, using crosstab

Transpose rows and columns (a.k.a. pivot) only with a minimum COUNT()?

守給你的承諾、 提交于 2019-12-19 05:54:26
问题 Here's my table 'tab_test': year animal price 2000 kittens 79 2000 kittens 93 2000 kittens 100 2000 puppies 15 2000 puppies 32 2001 kittens 31 2001 kittens 17 2001 puppies 65 2001 puppies 48 2002 kittens 84 2002 kittens 86 2002 puppies 15 2002 puppies 95 2003 kittens 62 2003 kittens 24 2003 puppies 36 2003 puppies 41 2004 kittens 65 2004 kittens 85 2004 puppies 58 2004 puppies 95 2005 kittens 45 2005 kittens 25 2005 puppies 15 2005 puppies 35 2006 kittens 50 2006 kittens 80 2006 puppies 95

Transpose rows and columns (a.k.a. pivot) only with a minimum COUNT()?

╄→гoц情女王★ 提交于 2019-12-19 05:54:18
问题 Here's my table 'tab_test': year animal price 2000 kittens 79 2000 kittens 93 2000 kittens 100 2000 puppies 15 2000 puppies 32 2001 kittens 31 2001 kittens 17 2001 puppies 65 2001 puppies 48 2002 kittens 84 2002 kittens 86 2002 puppies 15 2002 puppies 95 2003 kittens 62 2003 kittens 24 2003 puppies 36 2003 puppies 41 2004 kittens 65 2004 kittens 85 2004 puppies 58 2004 puppies 95 2005 kittens 45 2005 kittens 25 2005 puppies 15 2005 puppies 35 2006 kittens 50 2006 kittens 80 2006 puppies 95

Jasper Reports crosstab sorting with comparatorExpression

半腔热情 提交于 2019-12-18 11:33:08
问题 I'm trying to sort my dynamic columns in a cross tab according to some custom scheme. In the docs I found mention of comparatorExpression: Crosstab group bucket comparator expression. The result of this expression is used to sort the buckets, in ascending or descending order. If no comparator expression is specified, the natural order will be used. but I don't understand what the expression should look like. Can I somehow use a regular java comparator? Can someone share an example? 回答1: I've

Turning arbitrarily many rows into columns in PostgreSQL

血红的双手。 提交于 2019-12-18 09:30:54
问题 I have a table in Postgres that was designed to capture information in unstructured form and rebuild it. I need to re-apply some structure when exporting data from that table and am struggling. Currently, I have a table of the form: lbl | name | value ----|------------|-------- 1 | num | 1 1 | colour | "Red" 1 | percentage | 25.0 2 | num | 2 2 | colour | "Green" 2 | percentage | 50.0 3 | num | 3 3 | colour | "Blue" 3 | percentage | 75.0 And I need to generate a table in this form: lbl | num |