rows

MySQL: Is it possible to “INSERT if number of rows with a specific value is less than X”?

本秂侑毒 提交于 2020-01-04 04:27:05
问题 To give a simple analogy, I have a table as follows: id (PK) | gift_giver_id (FK) | gift_receiver_id (FK) | gift_date Is it possible to update the table in a single query in such a way that would add a row (i.e. another gift for a person) only if the person has less than 10 gifts so far (i.e. less than 10 rows with the same gift_giver_id)? The purpose of this would be to limit the table size to 10 gifts per person. Thanks in advance. 回答1: "And would that also be, 'otherwise, update the fields

In Apache Pig how can I serialise columns into rows?

久未见 提交于 2020-01-03 05:27:08
问题 In Apache Pig I want to serialise columns held in a variable into rows. More specifically: The data, loaded into the variable, look (via DUMP ) like (val1a, val2a,.... ) (val1b, val2b,val3b,.... ) (val1c, val2c,.... ) . . . and I want to transform this into (val1a) (val2a) . . . (val1b) (val2b) (val3b) . . . (val1c) (val2c) . . . So, each column has to be "serialised" into rows and then these rows are added subsequently. Please note: I do not necessarily know how many columns are in each row.

Spring mvc add multiple rows

落爺英雄遲暮 提交于 2020-01-02 07:04:05
问题 i need your help as the title says i have a problem inserting multiple rows from a jsp form. The code is from an answer from this site. Controller @ModelAttribute("programform") public ProgramForm populatePojos() { // Don't forget to initialize the pojos list or else it won't work ProgramForm programform = new ProgramForm(); List<Programs> programs = new ArrayList<Programs>(); for(int i=0; i<2; i++) { programs.add(new Programs()); } programform.setPrograms(programs); return programform; }

Row-wise cor() on subset of columns using dplyr::mutate()

笑着哭i 提交于 2020-01-02 07:01:33
问题 set.seed(8) df <- data.frame( A=sample(c(1:3), 10, replace=T), B=sample(c(1:3), 10, replace=T), C=sample(c(1:3), 10, replace=T), D=sample(c(1:3), 10, replace=T), E=sample(c(1:3), 10, replace=T), F=sample(c(1:3), 10, replace=T)) Would like to pass a subset of columns into a dplyr mutate() and make a row-wise calculation, for instance cor() to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration here, here and here, but nevertheless failed to produce an

Row-wise cor() on subset of columns using dplyr::mutate()

♀尐吖头ヾ 提交于 2020-01-02 07:01:09
问题 set.seed(8) df <- data.frame( A=sample(c(1:3), 10, replace=T), B=sample(c(1:3), 10, replace=T), C=sample(c(1:3), 10, replace=T), D=sample(c(1:3), 10, replace=T), E=sample(c(1:3), 10, replace=T), F=sample(c(1:3), 10, replace=T)) Would like to pass a subset of columns into a dplyr mutate() and make a row-wise calculation, for instance cor() to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration here, here and here, but nevertheless failed to produce an

merge row with next row in dataframe pandas

笑着哭i 提交于 2020-01-01 17:37:48
问题 I have a dataframe in pandas which contains multiple columns. I want to merge every row with the next row. Example: input dataframe: A B C a1 a2 a3 b1 b2 b3 c1 c1 c3 d1 d2 d3 output dataframe: A1 B1 C1 A2 B2 C2 a1 a2 a3 b1 b2 b3 b1 b2 b3 c1 c2 c3 c1 c2 c3 d1 d2 d3 d1 d2 d3 NaN NaN NaN The solusion I came up with was copying the original dataframe, changing the index to be index - 1, and then merging the two data frames by index. Is there any other solution? 回答1: Use shift with join, concat or

jQuery Mobile and textarea rows

▼魔方 西西 提交于 2020-01-01 05:42:09
问题 So, I'ld like to display a textarea on just 1 row. But jQuery Mobile doesn't think so... Whatever value I set in the rows attribute, it always is 2 rows height... Would it have any solution ? 回答1: The jQuery Mobile CSS sets a specific height for textarea elements: textarea.ui-input-text { height : 50px; -webkit-transition : height 200ms linear; -moz-transition : height 200ms linear; -o-transition : height 200ms linear; transition : height 200ms linear; } You can create your own rule to

How to retrieve match records across multiple tables in MySQL

不羁的心 提交于 2019-12-30 10:59:44
问题 I have two identical tables such as : table1 col1 col2 col3 col4 col5 table2 col1 col2 col3 col4 col5 I want to compare table 1 and 2 and find identical rows (col1, col2, col3, col4 etc..) between the 2 tables. I think we need to use vtable or something similar .. I tried SELECT * FROM TABLE1 WHERE COL1, COL2, COL3, COL4 IN (SELECT COL1, COL2, COL3, COL4 FROM TABLE2); It doesn't work .. help please :) 回答1: SELECT * FROM TABLE1 t WHERE EXISTS ( SELECT * FROM TABLE2 tt WHERE (COL1, COL2, COL3,

Mysql “select * from” doesn't return all rows

我与影子孤独终老i 提交于 2019-12-30 08:23:06
问题 I'm used to PostgreSQL and don't understand this behaviour on MySQL. This table (from SugarCRM) has 3057 rows: mysql> SELECT count(*) FROM tasks ; +----------+ | count(*) | +----------+ | 3057 | +----------+ But when running SELECT * FROM tasks : mysql> SELECT * FROM tasks ; ... 2344 rows in set (0,02 sec) I'm using a fairly old version of MySQL, but the issue is I'm just trying to dump the database and restore to a new version. # mysql --version mysql Ver 14.14 Distrib 5.1.51, for slackware

How to filter data based on one word of a column value?

▼魔方 西西 提交于 2019-12-29 09:34:07
问题 I have a dataframe that simplified looks like this only it has 2k rows. I'm wondering if there's a way to either extract data or filter data by the values in the LocationID column. I would like to extract rows that have the word "Creek" or "River" in them which would leave out the other names (such as the Banana Forest value). LocationID, Code Alk River, 232 Bala River, 4324 Banana Forest, 344 Cake River, 432 Alk Creek, 6767 Cake Creek, 766 Thank you! 回答1: We can do this with tidyverse