crosstab

Query for crosstab view

放肆的年华 提交于 2019-12-11 15:03:51
问题 I have a table in PostgreSQL like below: -------------------------------------------------------------- Item1 | Item2 | Item3 | Item4 |Value1| Value2| Value3| Value4| -------------------------------------------------------------- I want a query which will show this table like below: ItemHead| ValueHead --------------- Item1 | Value1| --------------- Item2 | Value2| ---------------- Item3 | Value3| ---------------- Item4 | Value4| --------------- 回答1: Use a single SELECT with a LATERAL join to

how to use MySQL for a dynamic pivot table or crosstab

爷,独闯天下 提交于 2019-12-11 13:59:33
问题 I know this question or a variance thereof has been asked multiple times, and I have even tried implementing a solution, but I am struggling in completing it. I have a very simple table with three data columns: Date1, Report_#, Name. I would like to pivot it around Date and the various names as the header tab, and have all the report numbers appear below. So it would LOOK like this: Report | Date | Name Date | Name1 | Name2 | Name3 ----------------------- ------------------------------ 1 | 4

Crosstab transpose query request

牧云@^-^@ 提交于 2019-12-11 13:57:37
问题 Using Postgres 9.3.4, I've got this table: create table tbl1(country_code text, metric1 int, metric2 int, metric3 int); insert into tbl1 values('us', 10, 20, 30); insert into tbl1 values('uk', 11, 21, 31); insert into tbl1 values('fr', 12, 22, 32); I need a crosstab query to convert it to this: create table tbl1(metric text, us int, uk int, fr int); insert into tbl1 values('metric1', 10, 11, 12); insert into tbl1 values('metric2', 20, 21, 22); insert into tbl1 values('metric3', 30, 31, 32);

Unexpected effect of filtering on result from crosstab() query with multiple values

时光怂恿深爱的人放手 提交于 2019-12-11 13:24:25
问题 I have a crosstab() query similar to the one in my previous question: Unexpected effect of filtering on result from crosstab() query The common case is to filter extra1 field with multiples values: extra1 IN(value1, value2...) . For each value included on the extra1 filter, I have added an ordering expression like this (extra1 <> valueN) , as appear on the above mentioned post. The resulting query is as follows: SELECT * FROM crosstab( 'SELECT row_name, extra1, extra2..., another_table

Looping in select query

那年仲夏 提交于 2019-12-11 13:19:35
问题 I want to do something like this: select id, count(*) as total, FOR temp IN SELECT DISTINCT somerow FROM mytable ORDER BY somerow LOOP sum(case when somerow = temp then 1 else 0 end) temp, END LOOP; from mytable group by id order by id I created working select: select id, count(*) as total, sum(case when somerow = 'a' then 1 else 0 end) somerow_a, sum(case when somerow = 'b' then 1 else 0 end) somerow_b, sum(case when somerow = 'c' then 1 else 0 end) somerow_c, sum(case when somerow = 'd'

Crosstab two columns under one column header Crystal Report

心已入冬 提交于 2019-12-11 12:41:51
问题 I want to create a report like in crystal report cross tab. The Table has the following data . I can get the report with three expected columns like SELF, 50% and 75%. and their output look like But my requirement is to use Increases and NPCalculated Columns under Main Column as mentioned in pic 1 above. Note: I used the NPCalculated in Summarized Fields but It gives me out like NPCalculated Value comes under Increases Value but It should be side by side as per my requirement. 回答1: First I

Dynamic Crosstab Query in MySQL

≡放荡痞女 提交于 2019-12-11 12:07:35
问题 I have a problem when switching from SQL Server to MySQL with Crosstab Query. Suppose that I have a table like this: | ID | BANKID | 1MONTH | 3MONTHS | 6MONTHS | 10MONTHS | 12MONTHS | 18MONTHS | 24MONTHS | 30MONTHS | 36MONTHS | |----|--------|--------|----------------|----------------|----------------|----------------|----------|----------------|----------------|----------------| | 1 | 1 | 3 | 2.900000095367 | 2.799999952316 | 2.700000047684 | 2.599999904633 | 2.5 | 2.400000095367 | 2

PostgreSQL merge two queries with COUNT and GROUP BY in each

陌路散爱 提交于 2019-12-11 11:16:41
问题 1st query: SELECT date_trunc('day', date1) as date, COUNT(*) AS count_a FROM table_a GROUP BY date result: date count_a 2014-04-01 00:00:00.0 1011642 2014-04-02 00:00:00.0 309048 2nd query: SELECT date_trunc('day', date1) as date, COUNT(*) AS count_b FROM table_b GROUP BY date result: date count_b 2014-04-01 00:00:00.0 2342 2014-04-02 00:00:00.0 43432 I'd like to get: date count_a count_b 2014-04-01 00:00:00.0 1011642 2342 2014-04-02 00:00:00.0 309048 43432 Is this possible? 回答1: A simple

Access '13 - Does not recognize field name Error, Crosstab to Report Issue

喜夏-厌秋 提交于 2019-12-11 11:11:47
问题 The Background Each month I run a crosstab query which is then "spruced up" with an Access Report. CROSSTAB SQL: TRANSFORM Sum(myTable.Field1) AS SumOfField1 SELECT myTable.Date, Sum(myTable.Field1) AS [Daily Totals] FROM myTable GROUP BY myTable.Date PIVOT myTable.Field2; where Field1 is a $ Amount, and Field2 (for this example) is either going to be "Option1", "Option2", or "Option3". TYPICAL CROSSTAB RESULTS: Date Option1 Option2 Option3 ----- -------- -------- -------- Day1 $5.00 -$2.37

Pixel values of raster records to be inserted in the table as columns

不想你离开。 提交于 2019-12-11 10:49:01
问题 I have a table with following columns: (ID, row_num, col_num, pix_centroid, pix_val1). I have more than 1000 records. I am inserting my data using: insert into pixelbased (row_num, col_num, pix_centroid, pix_val) select (ST_PixelAsPolygons(rast, 1)).x as X, (ST_PixelAsPolygons(rast, 1)).y as Y, (ST_Centroid((ST_PixelAsPolygons(rast, 1)).geom)) as geom, (ST_PixelAsPolygons(rast, 1)).val as pix_val1 from mytable where rid=1` Now I am trying to insert all the other records as a column and _pix