rows

Update multiple rows with different values in a single query - MySQL

☆樱花仙子☆ 提交于 2019-12-18 12:28:59
问题 I'm new to MySQL. I'm using this to update multiple rows with different values, in a single query: UPDATE categories SET order = CASE id WHEN 1 THEN 3 WHEN 2 THEN 4 WHEN 3 THEN 5 END, title = CASE id WHEN 1 THEN 'New Title 1' WHEN 2 THEN 'New Title 2' WHEN 3 THEN 'New Title 3' END WHERE id IN (1,2,3) I am using "WHERE" to improve performance (without it every row in the table would be tested). But what if I have this senario (when I don't want to update title for id 2 and 3): UPDATE

change data.frame column into rows in R

好久不见. 提交于 2019-12-18 11:49:50
问题 A <- c(1,6) B <- c(2,7) C <- c(3,8) D <- c(4,9) E <- c(5,0) df <- data.frame(A,B,C,D,E) df A B C D E 1 1 2 3 4 5 2 6 7 8 9 0 I would like to have this: df 1 2 A 1 6 B 2 7 C 3 8 D 4 9 E 5 0 回答1: If your dataframe is truly in that format, then all of your vectors will be character vectors. Or, you basically have a character matrix and you could do this: data.frame(t(df)) It would be better, though, to just define it the way you want it from the get-go df <- data.frame(c('A','B','C','D','E'), c

change data.frame column into rows in R

别等时光非礼了梦想. 提交于 2019-12-18 11:49:35
问题 A <- c(1,6) B <- c(2,7) C <- c(3,8) D <- c(4,9) E <- c(5,0) df <- data.frame(A,B,C,D,E) df A B C D E 1 1 2 3 4 5 2 6 7 8 9 0 I would like to have this: df 1 2 A 1 6 B 2 7 C 3 8 D 4 9 E 5 0 回答1: If your dataframe is truly in that format, then all of your vectors will be character vectors. Or, you basically have a character matrix and you could do this: data.frame(t(df)) It would be better, though, to just define it the way you want it from the get-go df <- data.frame(c('A','B','C','D','E'), c

Remove rows from a single-column data frame

怎甘沉沦 提交于 2019-12-18 06:11:29
问题 When I try to remove the last row from a single column data frame, I get a vector back instead of a data frame: > df = data.frame(a=1:10) > df a 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 > df[-(length(df[,1])),] [1] 1 2 3 4 5 6 7 8 9 The behavior I'm looking for is what happens when I use this command on a two-column data frame: > df = data.frame(a=1:10,b=11:20) > df a b 1 1 11 2 2 12 3 3 13 4 4 14 5 5 15 6 6 16 7 7 17 8 8 18 9 9 19 10 10 20 > df[-(length(df[,1])),] a b 1 1 11 2 2 12 3 3 13 4

UITableView rows load asynchronously

℡╲_俬逩灬. 提交于 2019-12-18 04:17:25
问题 On launch of app, i want to show 10 rows, at the bottom "Load 15 more", on click on "Load 15 more" the next 15 rows should add to the bottom of the table and again show "Load 15 more", until no rows found. note: I am using php to load table data as an xml feed. If anyone has any tutorial/sample code pl send me the link 回答1: This could be helpful: http://www.iphonedevsdk.com/forum/iphone-sdk-development/18876-paging-pagination-load-more-uitableview.html 回答2: I wrote something that might be

Select multiple rows with the same value(s)

浪尽此生 提交于 2019-12-17 22:34:24
问题 I have a table, sort of like this: ID | Chromosome | Locus | Symbol | Dominance | =============================================== 1 | 10 | 2 | A | Full | 2 | 10 | 2 | a | Rec. | 3 | 10 | 3 | B | Full | 4 | 10 | 3 | b | Rec. | I'd like to select all rows with the same locus and chromosome. For example, rows 3 and 4. There may be more than 2 at a time and they may not be in order. I tried this: SELECT * FROM Genes GROUP BY Locus HAVING Locus='3' AND Chromosome='10' But it always returns row 3,

How to add rows with 0 counts to summarised output

送分小仙女□ 提交于 2019-12-17 21:00:00
问题 I have added sample data below, I have used dplyr to count on Rco and month : structure(list(Rco = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L), .Label = c("A220", "B334", "C123", "D445" ), class = "factor"), month = structure(c(3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 4L, 2L, 4L, 3L), .Label = c("Apr", "Feb", "Jan", "Mar"), class = "factor"), count = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)), .Names = c("Rco", "month", "count"), row.names = c(NA, -13L), class = "data.frame"

Transpose mysql query rows into columns

我的未来我决定 提交于 2019-12-17 19:53:10
问题 I have a simple query that produces the below results: SELECT month,transporttype,count(transporttype) as loads from deliveries group by month,transporttype I would like to transpose the rows into columns. I understand mysql does not have pivot functions so a union is required but not 100% sure. Thanks in advance for the help. 回答1: You can do it with a crosstab like this - SELECT `year`, `month`, SUM(IF(`transporttype` = 'inbound', 1, 0)) AS `inbound`, SUM(IF(`transporttype` = 'LocalPMB', 1,

How to transfer the data of columns to rows (with awk)?

偶尔善良 提交于 2019-12-17 18:40:10
问题 I have a file like this: n A B C D 1 01 02 01 01 2 02 02 01 01 and I want to transfer the columns by rows, so the output should be like this: n 1 2 A 01 02 B 02 02 C 01 01 D 01 01 I have wrote this command: awk '{ for (i=1;i<=NF;i++ ) printf $i " " }' file.txt > out-file.txt the problem is that this command put everything on one line! so the output is like this: n 1 2 A 01 02 B 02 02 C 01 01 D 01 01 回答1: This might work: awk '{ for (f = 1; f <= NF; f++) { a[NR, f] = $f } } NF > nf { nf = NF }

Convert Database Rows into Columns

坚强是说给别人听的谎言 提交于 2019-12-17 17:12:40
问题 I need to convert Database rows into columns and show the result in Gridview. My DB is as follows: ID Hotel cDate Price ----------------------------------------------- 1 Hotel1 12/22/2009 12:00:00 AM 15.0000 2 Hotel2 12/22/2009 12:00:00 AM 25.0000 3 Hotel3 12/22/2009 12:00:00 AM 60.0000 4 Hotel4 12/22/2009 12:00:00 AM 55.0000 . . . I've to show the results as below: cDate Hotel1 Hotel2 Hotel3 Hotel4 12/22/2009 12:00:00 PM 15 25 60 55 12/22/2009 12:00:00 AM .. .. .. .. 12/22/2009 12:00:00 AM