pivot

Efficiently convert rows to columns in sql server

。_饼干妹妹 提交于 2020-01-07 04:07:13
问题 I'm looking for an efficient way to convert rows to columns in SQL server, I heard that PIVOT is not very fast, and I need to deal with lot of records. This is my example: ------------------------------- | Id | Value | ColumnName | ------------------------------- | 1 | John | FirstName | | 2 | 2.4 | Amount | | 3 | ZH1E4A | PostalCode | | 4 | Fork | LastName | | 5 | 857685 | AccountNumber | ------------------------------- This is my result: -----------------------------------------------------

Pivoting a table with predefined headers [closed]

北战南征 提交于 2020-01-07 03:18:07
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . ID | NAME | Description A A Value1 A A Value2 B B Value1 C C Value1 C C Value2 C C Value3 D D Value1 D D Value2 D D Value3 D D Value4 D D Value5 D D Value6 I have this input, and i am trying to convert it into this. ID | NAME | Desc1 | Desc2 | Desc3 | Desc4 | Desc5 | Desc6 A A Value1 Value2 B B

PowerBI - Pivot table drill down functionality

Deadly 提交于 2020-01-07 02:48:30
问题 I'm new to POWERBI, and am using it to combine multiple large files and summarize data for me. I'm trying to move away from EXCEL since the files can become large when sharing with others. I want to use ROW LEVEL SECURITY and grant access to specific users. My main question is, is there a PIVOT TABLE drill down function in POWERBI? I'm unable to find this anywhere in the menus and looking at their forums people are unsure, December 2015 they were "working on it," but there have been no

distinct values as new columns & count

走远了吗. 提交于 2020-01-07 02:26:26
问题 I'm trying to generate a summary from a table using SQLite as below. I need to aggregate 1) number of times each model was driven, 2) total distance driven & 3) get distinct values for driver col & count the number of times each driver has driven the particular model - GROUP BY model with COUNT(model) & SUM(distance) will help with 1 & 2 - `I need help with the last part #3 , what is the right approach to find number of occurrences for each distinct values of a column and add them as new

Pivot Data in MySQL by Month

时光毁灭记忆、已成空白 提交于 2020-01-07 01:50:20
问题 I have a table with this fields (model, date, price, quantity) I need a SQL (to MySQL) that gives me a dynamic table with the model name, the quantity and the gross sales (price*quantity), but separated by month (date). For example. April | May | June Model |quantity| Gross Sales| quantity|Gross Sales| quantity | Gross Sales 1 6 50 4 40 5 45 2 10 30 3 9 5 15 Thanks!! UPDATED: The table: CREATE TABLE `sales` ( `model` varchar DEFAULT NULL, `price` int DEFAULT NULL, `quantity` int(2) DEFAULT

Pivot Data in MySQL by Month

喜你入骨 提交于 2020-01-07 01:50:09
问题 I have a table with this fields (model, date, price, quantity) I need a SQL (to MySQL) that gives me a dynamic table with the model name, the quantity and the gross sales (price*quantity), but separated by month (date). For example. April | May | June Model |quantity| Gross Sales| quantity|Gross Sales| quantity | Gross Sales 1 6 50 4 40 5 45 2 10 30 3 9 5 15 Thanks!! UPDATED: The table: CREATE TABLE `sales` ( `model` varchar DEFAULT NULL, `price` int DEFAULT NULL, `quantity` int(2) DEFAULT

how to pivot rows to columns

主宰稳场 提交于 2020-01-06 14:58:30
问题 Every example of using PIVOT in MSSQL shows people using this to aggregate data. I'm trying to exploit this to just simply transpose rows to columns For instance, consider the follwoing data SELECT 11826 ID,cast('64 ' as varchar(1000)) as answer,75098 QuestionID,2785 CollectionID into #temp insert into #temp SELECT 11827 ID,cast('Security ' as varchar(1000)) as answer,75110 QuestionID,2785 CollectionID insert into #temp SELECT 11828 ID,cast('42 ' as varchar(1000)) as answer,75115 QuestionID

Pivot rows into columns

倾然丶 夕夏残阳落幕 提交于 2020-01-06 14:57:36
问题 I have an SQL query that generates the following: col1 | col2 | col3 ===================== item1 | key1 | value1 --------------------- item1 | key2 | value2 This is the query: SELECT t1.col1, t2.col2, t2.col3 FROM table1 t1 JOIN table2 t2 ON t1.id = t1.table1_id Data in table1: id | col1 ========= 1 | item1 2 | item1 Data in table2: table1_id | col2 | col3 ===================== 1 | key1 | item1 1 | key2 | item2 2 | key1 | item1 2 | key2 | item2 2 | key3 | item3 The number of rows is dynamic,

mysql transform fields to column

纵然是瞬间 提交于 2020-01-06 07:50:29
问题 I have the following tables table 1 table 2 id q_id content id w_id q_id c_id ranking ---------------------- ------------------------------------------------ 95 2046 1=E 123 22404 2046 100 1 96 2046 2=G 124 22404 2046 101 2 97 2046 3=N 125 22404 2046 102 2 98 2046 4=B 126 22404 2046 103 2 99 2046 5=V 127 22404 2046 104 3 100 2046 A1 128 22404 2046 105 3 101 2046 A2 102 2046 A3 103 2046 A4 104 2046 A5 105 2046 A6 I need to transfrom the table row to column The original Result: c_id content E G

The column 'ID' was specified multiple times for 'PivotTable'

▼魔方 西西 提交于 2020-01-06 07:47:48
问题 SELECT PartyRelationshipID,[2] AS OrderGroup,[3] AS TaxStatus,[4] AS Area FROM ( SELECT prs.PartyRelationshipID ,prs.PartyRelationshipSettingTypeID ,Value = CONVERT(INT, CASE WHEN IsNumeric(CONVERT(VARCHAR(12), prs.Value)) = 1 then CONVERT(VARCHAR(12), prs.Value) else 0 End) FROM [Party].PartyRelationshipSetting prs) AS SourceTable INNER JOIN Party.PartyRelationship prship ON SourceTable.PartyRelationshipID = prship.ID INNER JOIN Party.PartyRole pr ON prship.ToPartyRoleID = pr.ID INNER JOIN