rows

Convert SQL columns to rows

自作多情 提交于 2020-02-03 08:06:26
问题 I would like to split one records columns into multiple rows. If I have a SQL statement like the following: SELECT 1,2,3 Result: 1 | 2 | 3 How do I convert that to the following result? 1 2 3 I am currently using MS SQL 2008. 回答1: SELECT 1 UNION SELECT 2 UNION SELECT 3 回答2: To sum up the comments above: If you want to convert columns into rows, you will need to use the T-SQL UNPIVOT clause. If you want to split a single column that contains comma separated values, you will need to create a

Convert SQL columns to rows

泄露秘密 提交于 2020-02-03 08:06:25
问题 I would like to split one records columns into multiple rows. If I have a SQL statement like the following: SELECT 1,2,3 Result: 1 | 2 | 3 How do I convert that to the following result? 1 2 3 I am currently using MS SQL 2008. 回答1: SELECT 1 UNION SELECT 2 UNION SELECT 3 回答2: To sum up the comments above: If you want to convert columns into rows, you will need to use the T-SQL UNPIVOT clause. If you want to split a single column that contains comma separated values, you will need to create a

How Do I collapse rows on null values in t-sql?

 ̄綄美尐妖づ 提交于 2020-01-30 08:29:31
问题 I'm in a weird situation with my query. My objective is to display the total deposits and withdrawals from multiple transactions for each person and display them. I am getting multiple rows that I need to collapse into one. This all needs to happen in one query SELECT lastname, firsname, case when upper(category) = 'W' then sum(abs(principal)) end as Withdrawal, case when upper(category) = 'D' then sum(abs(principal)) end as Deposit, description FROM table1 JOIN table2 ON table1.id = table2

Add new row based on an if condition via Python

主宰稳场 提交于 2020-01-25 06:43:44
问题 I need to add a new row if two consecutive cells of the column door are the same and the difference between two consecutive cells in the column time is more than 5 minutes. df: Time door name 09:10:00 RDC_OUT-1 alex 09:10:00 RDC_OUT-1 alex 11:23:00 RDC_IN-1 alex 12:13:00 RDC_IN-1 alex 12:39:00 RDC_OUT-1 alex 15:23:00 RDC_IN-1 alex Code : import pandas as pd import numpy as np file_name='test.xlsx' from datetime import timedelta import datetime df = pd.read_excel(file_name, header=0, index=

How to get 1D column array and 1D row array from 2D array? (C# .NET)

戏子无情 提交于 2020-01-23 05:00:34
问题 i have double[,] Array; . Is it possible to get something like double[] ColumnArray0 = Array[0,].toArray() and double[] RowArray1 = Array[,1].toArray() without making a copy of every elemet(using for)? Thanks. 回答1: Arrays are a memory area where all entries are stored in a consecutive way. Depending on the data layout in memory this is only possible for either rows or columns. Instead of the 2d array double[,] type it is in your case better to use an array of arrays double[][] double[][]

Change row values to zero if less than row standard deviation

♀尐吖头ヾ 提交于 2020-01-21 11:42:28
问题 I want to change all values of a row to zero if they are less than the standard deviation of that row. set.seed(007) X <- data.frame(matrix(sample(c(5:50), 100, replace=TRUE), ncol=10)) X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 1 37 10 43 45 11 17 39 13 13 44 2 10 24 32 16 7 50 41 47 9 39 3 23 49 46 35 16 30 22 10 11 46 4 41 46 19 28 47 39 27 40 49 13 5 29 23 49 10 50 17 42 43 7 31 6 31 26 11 36 35 43 45 29 33 9 7 21 12 5 21 29 12 31 30 7 30 8 32 24 8 43 9 17 35 44 41 8 9 20 44 39 8 40 17 27 45 14 37 10

Update Multiple Rows in one PHP

妖精的绣舞 提交于 2020-01-21 10:27:22
问题 I have three rows with three columns in one table id type value 1 gold 1000.00 2 silver 32.21 3 platinum 1500.00 I have a form on my page with three inputs to fill in the updated values and am using ajax to send those values to update_values.php The code below works, but I am curious as to whether there is a more efficient / proper way of doing this. Thanks in advance for the knowledge-boost! PHP //Pull data from settings update $gold=$_POST['gold']; $silver=$_POST['silver']; $plat=$_POST[

numberOfRowsInSection: method for core data and multiple sections

假如想象 提交于 2020-01-19 13:09:10
问题 I am trying to show a table view with 2 sections. The first section will always have 1 row and the second section will have as many rows as data points. I am using Core Data and the following tableView:numberOfRowsInSection: method... - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return 1; } else { id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo

numberOfRowsInSection: method for core data and multiple sections

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-19 13:08:09
问题 I am trying to show a table view with 2 sections. The first section will always have 1 row and the second section will have as many rows as data points. I am using Core Data and the following tableView:numberOfRowsInSection: method... - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return 1; } else { id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo

How to get specific number of rows based on column values in dataframe [duplicate]

只谈情不闲聊 提交于 2020-01-16 08:36:07
问题 This question already has answers here : Pandas get topmost n records within each group (3 answers) Closed 2 years ago . Suppose I have a MNIST dataset in this way. df = pd.read_csv('data/train.csv') data = df.loc[df['label'].isin([1,6])] I am trying to select only those rows whose column ['label'] == 1 or 6. But, I am want to get only 500 rows from each column ['label'] How do I do it? 回答1: Use groupby first then filer i.e ndf= df.groupby('label').head(500) data = ndf.loc[ndf['label'].isin(