crosstab

Keeping same number of columns at cross tab report

六月ゝ 毕业季﹏ 提交于 2020-01-05 10:30:21
问题 I have a cross-tab report which similar to this Problem is when there are no data to one month that column won't appear in the report. I would like to keep the same number of column even there are empty values for the row data. Is it possible to achieve in cross-tab reports?? Thanks 回答1: This is a problem more with the underlying dataset. You have two options: Modify your query to always return data even for "empty" groups Hardcode the columns into the cross-tab Option 1 is probably the best

Access Crosstab subtotal columns

余生长醉 提交于 2020-01-05 07:39:48
问题 I have a following question regarding crosstabs in Access: How do I create a subtotal columns? What I want to see as a result of the query is this: Nov 2010 Dec 2010 2010 Total Jan 2011 Feb 2011 Row1 2 4 17 3 2 Row2 8 6 35 7 5 How do I create these subtotals for the year? (It's ok, if the year data will be in the end, after all months) The problem is that I need to do this without hardcoding each year, the query should work with any dataset Thanks in advance! 回答1: Say we have raw [SalesData]

Access Crosstab subtotal columns

安稳与你 提交于 2020-01-05 07:39:25
问题 I have a following question regarding crosstabs in Access: How do I create a subtotal columns? What I want to see as a result of the query is this: Nov 2010 Dec 2010 2010 Total Jan 2011 Feb 2011 Row1 2 4 17 3 2 Row2 8 6 35 7 5 How do I create these subtotals for the year? (It's ok, if the year data will be in the end, after all months) The problem is that I need to do this without hardcoding each year, the query should work with any dataset Thanks in advance! 回答1: Say we have raw [SalesData]

PostgreSQL crosstab() alternative with CASE and aggregates

我的梦境 提交于 2020-01-05 07:15:32
问题 I want to create a pivot table view showing month on month sum of bookings for every travel_mode . Table bookings : timestamp , bookings , provider_id Table providers : provider_id , travel_mode Pivot table function and crosstab functions are not to be used to do this. So I am trying to use JOIN and CASE. Following is the query: SELECT b.month, (CASE WHEN p.travel_mode=train then b.amount end)train, (CASE WHEN p.travel_mode=bus then b.amount end)bus, (CASE WHEN p.travel_mode=air then b.amount

Can the categories in the postgres tablefunc crosstab() function be integers?

丶灬走出姿态 提交于 2020-01-05 05:48:28
问题 It's all in the title. Documentation has something like this: SELECT * FROM crosstab('...') AS ct(row_name text, category_1 text, category_2 text); I have two tables, lab_tests and lab_tests_results . All of the lab_tests_results rows are tied to the primary key id integer in the lab_tests table. I'm trying to make a pivot table where the lab tests (identified by an integer) are row headers and the respective results are in the table. I can't get around a syntax error at or around the integer

How to filter a crosstab created in pandas by a specific column

余生颓废 提交于 2020-01-04 02:58:50
问题 I have created a cross tabulation in pandas using: grouped_missing_analysis = pd.crosstab(clean_sessions.action_type, clean_sessions.action, margins=True).unstack() print(grouped_missing_analysis[:20]) Which leads to displaying: action action_type 10 Missing 0 Unknown 0 booking_request 0 booking_response 0 click 0 data 0 message_post 3215 modify 0 partner_callback 0 submit 0 view 0 All 3215 11 Missing 0 Unknown 0 booking_request 0 booking_response 0 click 0 data 0 message_post 716 modify 0

PostgreSQL query with generated columns

做~自己de王妃 提交于 2019-12-31 05:27:10
问题 I have a schema as show like the below, and I want to run a query where I get a column in the output for every row of the points table. So for each usage row I want to multiply the amount of the usage times the amount for the referenced points_id , and then sum that up and group by person. So for the example data I'd want output that looked like this: Name | foo | bar | baz -------|------|------|------ Scott | 10.0 | 24.0 | 0.0 Sam | 0.0 | 0.0 | 46.2 Here's the schema/data: CREATE TABLE

PostgreSQL says “return and sql tuple descriptions are incompatible”

江枫思渺然 提交于 2019-12-30 04:28:09
问题 I have the following data: ID CLASS VALUE 1 NHB 700905.7243 1 HBW 164216.1311 1 HBO 700905.7243 2 NHB 146023.3792 2 HBW 89543.2972 2 HBO 82152.072 3 NHB 1409818.328 3 HBW 220430.7922 3 HBO 323512.9391 4 NHB 48711.3814 4 HBW 163385.1575 4 HBO 363352.3441 That I want to reorganize as: ID HBO HBW NHB 1 700905.7243 164216.1311 700905.7243 2 82152.072 89543.2972 146023.3792 3 323512.9391 220430.7922 1409818.328 4 363352.3441 163385.1575 48711.3814 Please note that the values in columns HBW, HBO

visualizing crosstab tables with a plot in R

房东的猫 提交于 2019-12-29 17:44:13
问题 I saw a plot generated in excel and I was wondering if R could also do it. This picture is essentially a visualization of a crosstab table comparing the days of the week to preferred meals on that day and counting the number of people that fall within those categories. I've read up on some R bubble charts but I have yet to see one like this. Can someone point me to a package or a website that explains how I can make a plot like this one? 回答1: Using Hadley Wickham's ggplot2 : library(ggplot2)