crosstab

How to flatten a PostgreSQL result

Deadly 提交于 2021-02-19 05:04:28
问题 I have experiments, features, and feature_values. Features have values in different experiments. So I have something like: Experiments: experiment_id, experiment_name Features: feature_id, feature_name Feature_values: experiment_id, feature_id, value Lets say, I have three experiments (exp1, exp2, exp3) and three features (feat1, feat2, feat3). I would like to have a SQL-result that looks like: feature_name | exp1 | exp2 | exp3 -------------+------+------+----- feat1 | 100 | 150 | 110 feat2 |

postgres crosstab, ERROR: The provided SQL must return 3 columns

时间秒杀一切 提交于 2021-02-10 20:52:43
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

postgres crosstab, ERROR: The provided SQL must return 3 columns

北城以北 提交于 2021-02-10 20:51:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

postgres crosstab, ERROR: The provided SQL must return 3 columns

让人想犯罪 __ 提交于 2021-02-10 20:50:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

FTR calculation using Google Query function

十年热恋 提交于 2021-02-08 11:41:18
问题 I am trying to create crosstabs pivot tables using Google Query function to calculate Employees First Time Resolution (FTR) rate based on the number of Issues received while booking Opportunities vs Total Opportunities booked . +---------+-------+---------+-----------+--------+-------+ | OppName | OppID | EmpName | MonthYear | Status | Issue | +=========+=======+=========+===========+========+=======+ | abc | 1000 | alex | 2020-Jan | active | yes | +---------+-------+---------+-----------+---

FTR calculation using Google Query function

别说谁变了你拦得住时间么 提交于 2021-02-08 11:40:04
问题 I am trying to create crosstabs pivot tables using Google Query function to calculate Employees First Time Resolution (FTR) rate based on the number of Issues received while booking Opportunities vs Total Opportunities booked . +---------+-------+---------+-----------+--------+-------+ | OppName | OppID | EmpName | MonthYear | Status | Issue | +=========+=======+=========+===========+========+=======+ | abc | 1000 | alex | 2020-Jan | active | yes | +---------+-------+---------+-----------+---

Making `group by` result in multiple columns

ぃ、小莉子 提交于 2021-02-08 08:00:32
问题 I have a ( Postgres ) query with a usual group by clause: select extract(year from a.created) as Year,a.testscoreid, b.irt_tlevel, count(a.*) as Questions from asmt.testscores a join asmt.questions b on a.questionid = b.questionid where a.answered = True group by Year,a.testscoreid, b.irt_tlevel order by Year desc, a.testscoreid The column b.irt_tlevel has values low , medium and high , all these results are in a row-format, for example: Year TestScoreId Irt_tlevel Questions 2015 1 Low 2 2015

Making `group by` result in multiple columns

亡梦爱人 提交于 2021-02-08 07:59:30
问题 I have a ( Postgres ) query with a usual group by clause: select extract(year from a.created) as Year,a.testscoreid, b.irt_tlevel, count(a.*) as Questions from asmt.testscores a join asmt.questions b on a.questionid = b.questionid where a.answered = True group by Year,a.testscoreid, b.irt_tlevel order by Year desc, a.testscoreid The column b.irt_tlevel has values low , medium and high , all these results are in a row-format, for example: Year TestScoreId Irt_tlevel Questions 2015 1 Low 2 2015

Oracle SQL Cross Tab Query

左心房为你撑大大i 提交于 2021-02-08 07:28:41
问题 I have a table which has the following structure and sample data: ITEM LOC STOCK 0001 KS5 10 0001 KS6 30 0002 KS5 10 0002 KS6 20 I need to query cross tab so that I get ITEM KS5 KS6 0001 10 30 0002 10 20 The LOC (KS5 and KS6) can vary and new locations can be added. How can I get the desired result? 回答1: For dynamically generated results you need some dynamic PLSQL solution, something like this procedure creating view v_list_loc : create or replace procedure p_list_loc is v_sql varchar2(32000

tidyverse: Cross tables of one variable with all other variables in data.frame

独自空忆成欢 提交于 2021-02-07 19:06:56
问题 I want to make cross table of a variable with all other variables in the data.frame. library(tidyverse) library(janitor) humans <- starwars %>% filter(species == "Human") humans %>% janitor::tabyl(gender, eye_color) gender blue blue-gray brown dark hazel yellow female 3 0 5 0 1 0 male 9 1 12 1 1 2 humans %>% dplyr::select_if(is.character) %>% dplyr::select(-name, -gender) %>% purrr::map(.f = ~janitor::tabyl(dat = humans, gender, .x)) Error: Unknown columns `blond`, `none`, `brown`, `brown,