crosstab

Is there a way to pivot rows to columns in MySQL without using CASE?

时间秒杀一切 提交于 2019-12-28 16:16:40
问题 There are lots of posts out there on pivoting rows into columns for various databases. They seem to fall into two camps, using case statements or using a built in function of the database vendor. I am using MySQL and have not found anything so far on any built in function that will allow me to pivot on an arbitrary unknown number of row values that I want to pivot into columns. If I don't know the values ahead of time, I can't build the CASE queries that appear frequently on stackoverflow. I

Java Crosstab - preparedstatement query

≯℡__Kan透↙ 提交于 2019-12-28 06:44:25
问题 I have a typical crosstab query with static parameters. It works fine with createStatement. I want to use preparestatement to query instead. String query = "SELECT * FROM crosstab( 'SELECT rowid, a_name, value FROM test WHERE a_name = ''att2'' OR a_name = ''att3'' ORDER BY 1,2' ) AS ct(row_name text, category_1 text, category_2 text, category_3 text);"; PreparedStatement stat = conn.prepareStatement(query); ResultSet rs = stat.getResultSet(); stat.executeQuery(query); rs = stat.getResultSet()

Execute a dynamic crosstab query

拜拜、爱过 提交于 2019-12-27 12:28:02
问题 I implemented this function in my Postgres database: http://www.cureffi.org/2013/03/19/automatically-creating-pivot-table-column-names-in-postgresql/ Here's the function: create or replace function xtab (tablename varchar, rowc varchar, colc varchar, cellc varchar, celldatatype varchar) returns varchar language plpgsql as $$ declare dynsql1 varchar; dynsql2 varchar; columnlist varchar; begin -- 1. retrieve list of column names. dynsql1 = 'select string_agg(distinct '||colc||'||'' '|

Execute a dynamic crosstab query

拈花ヽ惹草 提交于 2019-12-27 12:27:10
问题 I implemented this function in my Postgres database: http://www.cureffi.org/2013/03/19/automatically-creating-pivot-table-column-names-in-postgresql/ Here's the function: create or replace function xtab (tablename varchar, rowc varchar, colc varchar, cellc varchar, celldatatype varchar) returns varchar language plpgsql as $$ declare dynsql1 varchar; dynsql2 varchar; columnlist varchar; begin -- 1. retrieve list of column names. dynsql1 = 'select string_agg(distinct '||colc||'||'' '|

Crystal Reports Cross-Tab Column Totals as Variables

妖精的绣舞 提交于 2019-12-25 02:49:19
问题 I have a report within Crystal 2008 that has 2 subreports, each of which is a Crosstab. I have split them into different reports as their selection and database queries are unrelated. What i need to be able to to is to create a variable for each of the Column Totals and be able to pass this onto a third report for each of the two cross Tabs. The Layout of each cross tab is formatted the same, with the columns being the PO Number and the rows being charges against each PO. It is the total of

Python Pandas Crosstabs

大城市里の小女人 提交于 2019-12-25 02:48:12
问题 New to Pandas and fairly new to Python. I’m trying to produce a crosstabs report from the following data – just showing a few rows. PALLET_ID AISLE NUM_PALLETS 7197033 AH 1 7197035 AC 1 7197035 AC 1 7197035 AC 1 7197035 AC 1 7197035 AC 1 I Sofastats I get a simple crosstab table of frequency of pallets within aisles - I.e. pallets down the left and aisles along the top. (New Stackoverflow account doesn't allow images). I am trying to do this in Pandas. import pandas as pd import numpy as np

t-sql most efficient row to column? crosstab for xml path, pivot

烂漫一生 提交于 2019-12-24 16:32:31
问题 I am looking for the most performant way to turn rows into columns. I have a requirement to output the contents of the db (not actual schema below, but concept is similar) in both fixed width and delimited formats. The below FOR XML PATH query gives me the result I want, but when dealing with anything other than small amounts of data, can take awhile. select orderid ,REPLACE(( SELECT ' ' + CAST(ProductId as varchar) FROM _details d WHERE d.OrderId = o.OrderId ORDER BY d.OrderId,d.DetailId FOR

MySQL Crosstab / Pivot Aggregation. Removing counts based on column in other table

╄→尐↘猪︶ㄣ 提交于 2019-12-24 15:42:58
问题 THE DATA I have a set of data in the following format: CAR_INVENTORY TABLE CAR_ID MAKE_MODEL COLOR YEAR 1 Ford Fusion Black 2015 2 Tesla Model S White 2014 3 Acura ILX Blue 2013 4 Ford Fusion Black 2013 5 Toyota Corolla Blue 2014 6 Ford Fusion Blue 2013 7 Toyota Corolla Blue 2012 8 Acura ILX Black 2015 9 Ford Focus Blue 2012 10 Ford Fusion White 2013 11 Acura ILX Black 2012 12 Toyota Corolla Black 2015 13 Toyota Corolla Blue 2014 14 Ford Focus White 2015 15 Tesla Model S Red 2015 16 Acura TLX

ireport crosstab with generic column group?

我们两清 提交于 2019-12-24 14:57:52
问题 I have a problem with JasperReports crosstab report. For example, I have data that currently is in this format: | Date | salesman | area | outlet | ----------------------------------------------------- | Date A | Salesman A | Area A | Outlet A | | Date A | Salesman A | Area A | Outlet B | | Date A | Salesman A | Area A | Outlet C | | Date B | Salesman B | Area A | Outlet A | | Date B | Salesman B | Area A | Outlet D | I need to output the data in this format: Date | Salesman | Area | Outlet 1

Cognos Calculate Variance Crosstab (Relational)

霸气de小男生 提交于 2019-12-24 12:09:36
问题 I have a simple crosstab such as this: Trans | Pants | Shirts | | 2013 | 2014 | 2013 | 2014 | --------------------------------------- Jan | 33 | 37 | 41 | 53 | Feb | 31 | 33 | 38 | 43 | Mar | 26 | 29 | 51 | 56 | Pants and Shirt belong to the data item: Category Years belong to the data item: Years Months belong to the data item: Months Trans (transactions) belongs to the data item: Trans Here is what is looks like in report studio: Trans | <#Category#> | <#Category#> | | <#Years#> | <#Years#>