pivot

Represent multiple rows of data in one column as multiple columns in one row SQL server

依然范特西╮ 提交于 2020-01-15 23:39:27
问题 I have a table with the following structure and data: batsman | runs | year 1 | 800 | 2012 1 | 950 | 2011 1 | 1050 | 2010 2 | 550 | 2012 2 | 650 | 2011 2 | 400 | 2010 3 | 900 | 2012 This data needs to be Selected through a sql query as: batsman | 2012 | 2011 | 2010 1 | 800 | 950 | 1050 2 | 550 | 650 | 400 3 | 900 | - | - I'm trying to do this through a stored proc. The assumption can be made that the number of columns (in terms of years) is fixed: 3. Also note, there are no arithmetic

PIVOT columns in SQL Server with their SUM

六眼飞鱼酱① 提交于 2020-01-15 12:23:33
问题 In reference to my previous Question . With these changes in the tables : (*) are used to mark the changes in the tables. Products Table prod_ID - int prod_Name - varchar(100) prod_Code - varchar(100) *prod_Price- float Orders Table ord_ID - int ord_Qty - int prod_ID - int cus_ID - float *ord_PurchaseType - varchar(100) Given that all items are priced as 10 dollars each. I want to make the final report to be something like this. Currently, I'm using something like this: SUM(CASE WHEN ord

How to make Column to Row without an aggregate function in sql server 2005/8?

浪尽此生 提交于 2020-01-15 10:11:40
问题 For example, I need to change from to . I know PIVOT is for that, but it requires an aggregate function; and for my case, I donot need to aggregate only need column to row. You can use the following sample data: CREATE TABLE[StudentScores] ( [UserName] NVARCHAR(20), [Subject] NVARCHAR(30), [Score]FLOAT, ) GO INSERT INTO[StudentScores]SELECT'Nick','Chinese',80 INSERT INTO[StudentScores]SELECT'Nick','Maths',90 INSERT INTO[StudentScores]SELECT'Nick','English',70 INSERT INTO[StudentScores]SELECT

SQL Server Pivot Table with multiple column with dates

[亡魂溺海] 提交于 2020-01-15 06:35:12
问题 I have a PIVOT situation. Source table columns: Title Description Datetime RecordsCount A California 2015-07-08 10:44:39.040 5 A California 2015-07-08 12:44:39.040 6 A California 2015-05-08 15:44:39.040 3 B Florida 2015-07-08 16:44:39.040 2 B Florida 2015-05-08 19:44:39.040 4 Now I need this pivoted as 2015-07-08 2015-05-08 Title Description A California 11 3 B Florida 2 4 if we have two record counts on same dates (no matter of time) then sum them, else display in different column. Trying to

Fetch table rows in columns

微笑、不失礼 提交于 2020-01-14 18:47:12
问题 I want get a special result from my table and i want find out that is possible !? I have a table like this: (idA , idB , val) by this values: idA | idB | val ----+-------+---------- 1 | 5 | 50 1 | 6 | 0 1 | 7 | NULL 2 | 5 | 100 2 | 6 | 12 2 | 7 | 0 I want select from this table by a format like this: idA | 5 | 6 | 7 ----+-------+-------+------- 1 | 50 | 0 | NULL 2 | 100 | 12 | 0 How it's possible? Note: I have some searches and find nothing, if you know a good key word it would be useful for

SQL Server Query for Many to Many Relationship - how to query?

泄露秘密 提交于 2020-01-14 04:29:06
问题 This is an update to my previous question : Many to many relationship The previous solution works fine, but now I want tgo improve the results a little bit. I´d like to have all the wavelength values in one row. So instead of the following result : DateTimeID Wavelength SensorID 11435 1581,665 334 11435 1515,166 334 11435 1518,286 335 I'd like to have something similar to this: DateTimeID Wavelength1 Wavelength2 SensorID 11435 1581,665 1515,166 334 11435 1518,286 335 回答1: You could use the

SQL Server pivot on 2 (or multiple) aggregates

限于喜欢 提交于 2020-01-13 19:46:35
问题 Is it possible to pivot on multiple aggregated columns in SQL Server? I have the following order table: [ORDERS] | CustName | OrderedProduct | QtyOrdered | UnitCost | UnitPrice | OrderDate Bob | Canned Tuna | 6 | 11 | 14 | 21-12-2016 13:11:00 Steve | Canned Salmon | 2 | 15 | 19 | 03-11-2016 11:03:00 Bob | Canned Tuna | 10 | 10 | 13 | 22-12-2016 10:43:00 Bob | Canned Tuna | 4 | 9 | 10 | 13-11-2016 17:22:00 I have the following pivot query which gives me an order quantity per product per

SQL Server pivot on 2 (or multiple) aggregates

你离开我真会死。 提交于 2020-01-13 19:46:05
问题 Is it possible to pivot on multiple aggregated columns in SQL Server? I have the following order table: [ORDERS] | CustName | OrderedProduct | QtyOrdered | UnitCost | UnitPrice | OrderDate Bob | Canned Tuna | 6 | 11 | 14 | 21-12-2016 13:11:00 Steve | Canned Salmon | 2 | 15 | 19 | 03-11-2016 11:03:00 Bob | Canned Tuna | 10 | 10 | 13 | 22-12-2016 10:43:00 Bob | Canned Tuna | 4 | 9 | 10 | 13-11-2016 17:22:00 I have the following pivot query which gives me an order quantity per product per

Pandas - Convert columns to new rows after groupby

人盡茶涼 提交于 2020-01-13 06:15:49
问题 I have a pandas dataframe. I need to convert some of the columns into rows. The dataframe has same data in the first two columns for every 3 rows. So, I need 6 more columns as you will see in my expected dataframe. I have the following dataframe: shopCode Product Code Score 111 Apple 123 0.70 111 Apple 456 0.75 111 Apple 789 0.80 222 Orange 142 0.66 222 Orange 136 0.83 222 Orange 623 0.76 My expected dataframe is: shopCode Product Code1 Code2 Code3 Score1 Score2 Score3 111 Apple 123 456 789 0

Android setting pivot point for scale animation

我与影子孤独终老i 提交于 2020-01-12 12:24:13
问题 I am trying to scale views to a certain size but can't quite understand how pivoting works. Say I want to scale the view upwards only. What value should the "pivotY" hold? In XML, it is a percentage. How is it when applying pivot point programmatically? Example: ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", scaleSize); ObjectAnimator pivotY = ObjectAnimator.ofFloat(view, "pivotY", pivotPoint); AnimatorSet set = new AnimatorSet(); set.PlayTogether(scaleY, pivotY); 回答1: Quite