pivot

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

别等时光非礼了梦想. 提交于 2020-01-06 07:47:06
问题 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

How to pivot this table in SQL

人走茶凉 提交于 2020-01-06 06:07:54
问题 I came across this issue when trying to make use of this "active users" table from Microsoft NAV. What I got asked to do is a Dashboard in Power BI or other tool that will allow the company I work for to understand how many users are active on the NAV system at any point in time. I found a DAX formula in Power BI that could do the trick - but it requires the following table transformation: I am trying to do this in SQL Management Studio: My SQL Server is Microsoft SQL Azure (RTM) - 12. How

PostgreSQL crosstab doesn't work as desired

一曲冷凌霜 提交于 2020-01-06 04:34:06
问题 In this example, I expect the resulting pivot table to have values for 4 columns, but instead there's only values for 2. It should've returned something like this: | time | trace1 | trace2 | trace3 | trace4 | | -----------------------------------------| | t | v | v | v | v | | t | v | v | v | null | | t | null | v | v | v | | t | v | v | null | v | | t | v | null | v | v | |------------------------------------------| but I got this instead: | time | trace1 | trace2 | trace3 | trace4 | | -----

sql query to select records in a specific format (using pivot or other)

橙三吉。 提交于 2020-01-06 04:29:13
问题 I have an SQL table like this: Animal1 Animal2 Corelation ---------+---------------+-------------- Cat Cat 1 Cat Dog 0.6 Cat Mouse 0.8 Dog Cat 0.6 Dog Dog 1 Dog Mouse 0.4 Mouse Cat 0.8 Mouse Dog 0.4 Mouse Mouse 1 I'm looking for an SQL query to return the following results: Animal 1 Cat Dog Mouse ---------+---------------+------------------+---------------+ Cat 1 0.6 0.8 Dog 6 1 0.4 Mouse 0.8 0.4 1 Basically i want more readable version of the table. I tried to use pivot like this: use

Excel VBA - Pivot Table with Multiple Value Filters

这一生的挚爱 提交于 2020-01-06 04:11:22
问题 Is there a way in Excel VBA to allow for multiple value filters in a Pivot Table? I'm trying to filter values for >0 AND for Bottom Ten items. In the sample code below (generated by recording a Macro), the second filter step overrides the first. If multiple value filters were supported, it seems I would only need to add the Boolean logic AND between these two expressions to get the product of both filters. Please suggest any changes to the code or let me know if this is not supported. Thanks!

sql date range in column and count by group

最后都变了- 提交于 2020-01-06 03:55:06
问题 I am trying to get a report where you can select a date range and get some counts. My table is something like this -------------------------------------- RecID|AgentID|date -------------------------------------- 1 |00123 | 05/09/2012 16:28:49 2 |00123 | 05/09/2012 17:28:49 3 |00124 | 05/09/2012 18:28:49 4 |00124 | 06/09/2012 19:28:49 5 |00125 | 06/09/2012 20:28:49 I want something like -------------------------------------- AgentID|05/09/2012|06/09/2012 --------------------------------------

pandas transform dataframe pivot table

孤街浪徒 提交于 2020-01-06 03:19:11
问题 I can transform the following dataframe: VALUE COUNT RECL_LCC RECL_PI 0 1 15,686,114 3 1 1 2 27,537,963 1 1 2 3 23,448,904 1 2 3 4 1,213,184 1 3 4 5 14,185,448 3 2 5 6 13,064,600 3 3 6 7 27,043,180 2 2 7 8 11,732,405 2 1 8 9 14,773,871 2 3 into something like this: RECL_PI 1 2 3 RECL_LCC 1 27,537,963 23,448,904 1,213,184 2 11,732,405 27,043,180 14,773,871 3 15,686,114 14,185,448 13,064,600 by using pandas pivot table: plot_table = LCC_PI_df.pivot_table(index=['RECL_LCC'], columns='RECL_PI',

Dynamic table creation in SQL Server [duplicate]

早过忘川 提交于 2020-01-06 02:50:06
问题 This question already has answers here : SQL Server: Examples of PIVOTing String data (7 answers) Closed 5 years ago . I have a situation like this +---------+-----------+------------+ | FieldNo | FieldName | Substring | +---------+-----------+------------+ | 1 | A | 8 | | 1 | A | A | | 1 | A | DC | | 2 | B | 7 | | 3 | C | 22 | | 3 | C | 37 | +---------+-----------+------------+ Need output like this: +----+------+------+ | A | B | C | +----+------+------+ | 8 | 7 | 22 | | A | Null | 37 | |

Cannot pivot table with my query?

走远了吗. 提交于 2020-01-05 07:58:07
问题 I have a table which looks like this - Id AttributeName AttributeValue A1 Atr1 A1V1 A1 Atr2 A1V2 A1 Atr3 A1V3 A2 Atr1 A2V1 A2 Atr2 A2V2 A2 Atr3 A3V3 Each ID in this table has the exact same attributes, ie ATR1, ATR2, ATR3. The values of these attributes is unique. I want to pivot this table and get the following output - Id Atr1 Atr2 Atr3 A1 A1V1 A1V2 A1V3 A2 A2V1 A2V2 A2V3 How do I do this ? I tried a query and it failed with the error - Msg 156, Level 15, State 1, Line 21 Incorrect syntax

Pandas: Pivot to True/False, drop column

徘徊边缘 提交于 2020-01-05 07:09:17
问题 I'm trying to create what I think is a simple pivot table but am having serious issues. There are two things I'm unable to do: Get rid of the "partner" column at the end. Set the values to either True or False if each company has that partner. Setup: df = pd.DataFrame({'company':['a','b','c','b'], 'partner':['x','x','y','y'], 'str':['just','some','random','words']}) Desired Output: company x y a True False b True True c False True I started with: df = df.pivot(values = 'partner', columns =