concat

Select records matching concat value of two fields in mongodb

北战南征 提交于 2019-11-28 02:51:01
问题 Is there a way to do something like this on MongoDB? select * from table where concat(field1, field2) = 'value' To clarify, I have an array of full names, but the documents have firstname and lastname separate, so I want to do something like select * from table where concat(firstname, lastname) in ([ARRAY OF NAMES]) 回答1: You can only do it with aggregation framework, not with regular find. db.coll.aggregate({$project:{newField:{$concat:["$field1","$field2"]}}}, {$match:{newField:"value"}} );

Inner Join Two Table, aggregating varchar fields

亡梦爱人 提交于 2019-11-28 01:45:37
Sorry I change my question a bit . I have two table and I want to merge them TERMS_TABLE ID | TERMS 309 | 'hardware' 309 | 'software' TFIDF_TABLE ID | TERMS 309 |'computer,phone,mp3....' Now I want to add TERMS column of TERMS_TABLE to terms column of TFIDF_TABLE like that result should be: NEW_TFIDF_TABLE ID | TERMS 309 |'computer,phone,mp3....,hardware,software' I try this code: Insert into NEW_TFIDF_TABLE SELECT T.ID, T.TERMS ||', '|| TT.TERMS FROM TFIDF_TABLE T INNER JOIN TERMS_TABLE TT ON T.ID=TT.ID but it does not do what I want How can I do that ? Modification: I forgot an issue. If

MySQL: Fill a table within a Stored Procedure efficiently

不羁的心 提交于 2019-11-27 23:20:42
I am testing performance in a MySQL Server and filling a table with more than 200 million of records. The Stored Procedure is very slow generating the big SQL string. Any help or comment is really welcome. System Info: Database: MySQL 5.6.10 InnoDB database (test). Processor: AMD Phenom II 1090T X6 core, 3910Mhz each core. RAM: 16GB DDR3 1600Mhz CL8. HD: Windows 7 64bits SP1 in SSD, mySQL installed in SSD, logs written in mechanical hard disk. The Stored Procedure creates a INSERT sql query with all the values to be inserted into the table. DELIMITER $$ USE `test`$$ DROP PROCEDURE IF EXISTS

Pandas concat yields ValueError: Plan shapes are not aligned

怎甘沉沦 提交于 2019-11-27 21:02:05
I am quite new to pandas, I am attempting to concatenate a set of dataframes and I am getting this error: ValueError: Plan shapes are not aligned My understanding of .concat() is that it will join where columns are the same, but for those that it can't find it will fill with NA. This doesn't seem to be the case here. Heres the concat statement: dfs = [npo_jun_df, npo_jul_df,npo_may_df,npo_apr_df,npo_feb_df] alpha = pd.concat(dfs) user3805082 In case it helps, I have also hit this error when I tried to concatenate two data frames (and as of the time of writing this is the only related hit I can

MySQL连接字符串函数CONCAT,CONCAT_WS,GROUP_CONCAT使用总结

老子叫甜甜 提交于 2019-11-27 20:23:34
在Mysql中两个字符串相加不能用+号,加号是用来做数字相加的,在mysql中要连接字符串需要用CONCAT或者CONCAT_WS函数: Mysql CONCAT函数 语法: CONCAT(str1,str2...) 例如: select OCNCAT('AB','CD') 将输出ABCD 需要注意的是: SELECT CONCAT('abc',NULL)其中有一个字符串为NULL时将输出NULL Mysql 的CONCAT_WS函数 的CONCAT_WS函数()函数, 表示concat with separator,即有分隔符的字符串连接 select concat_ws(',','11','22','33'); 输出: 11,22,33 需注意concat_ws的参数中有null的话,并非都返回null,例如concat_ws(',','ab',NULL)将输出ab Mysql的GROUP_CONCAT()函数 从名字可以看出这个函数是一个聚合函数,在group语句中使用,可以将多行的字符串按分组整合成一个字符串。 语法: GROUP_CONCAT([DISTINCT] expr [,expr ...][ORDER BY {unsigned_integer | col_name | expr} [ASC | DESC] [,col_name ...]][SEPARATOR

concat和concat_ws()区别及MySQL的几个实用字符串函数【转】

时间秒杀一切 提交于 2019-11-27 20:23:06
1、 concat () 函数 1.1 MySQL的concat函数可以连接一个或者多个字符串 , 如 mysql > select concat ( '10' ); +--------------+ | concat ( '10' ) | +--------------+ | 10 | +--------------+ 1 row in set ( 0.00 sec ) mysql > select concat ( '11' , '22' , '33' ); +------------------------+ | concat ( '11' , '22' , '33' ) | +------------------------+ | 112233 | +------------------------+ 1 row in set ( 0.00 sec ) 而Oracle的concat函数只能连接两个字符串 SQL > select concat ( '11' , '22' ) from dual ; 1.2 MySQL的concat函数在连接字符串的时候,只要其中一个是NULL , 那么将返回NULL mysql > select concat ( '11' , '22' , null ); +------------------------+ | concat ( '11'

Prepend text to beginning of string

…衆ロ難τιáo~ 提交于 2019-11-27 19:12:43
What is the fastest method, to add a new value at the beginning of a string? Thor Jacobsen var mystr = "Doe"; mystr = "John " + mystr; Wouldn't this work for you? You could do it this way .. var mystr = 'is my name.'; mystr = mystr.replace (/^/,'John '); console.log(mystr); disclaimer: http://xkcd.com/208/ ES6: let after = 'something after'; let text = `before text ${after}`; chirag you could also do it this way "".concat("x","y") Since the question is about what is the fastest method, I thought I'd throw up add some perf metrics. TL;DR The winner, by a wide margin, is the + operator, and

pandas concat ignore_index doesn't work

寵の児 提交于 2019-11-27 18:20:29
I am trying to column-bind dataframes and having issue with pandas concat , as ignore_index=True doesn't seem to work: df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], 'B': ['B0', 'B1', 'B2', 'B3'], 'D': ['D0', 'D1', 'D2', 'D3']}, index=[0, 2, 3,4]) df2 = pd.DataFrame({'A1': ['A4', 'A5', 'A6', 'A7'], 'C': ['C4', 'C5', 'C6', 'C7'], 'D2': ['D4', 'D5', 'D6', 'D7']}, index=[ 5, 6, 7,3]) df1 # A B D # 0 A0 B0 D0 # 2 A1 B1 D1 # 3 A2 B2 D2 # 4 A3 B3 D3 df2 # A1 C D2 # 5 A4 C4 D4 # 6 A5 C5 D5 # 7 A6 C6 D6 # 3 A7 C7 D7 dfs = [df1,df2] df = pd.concat( dfs,axis=1,ignore_index=True) print df and the

Concatenate a list of pandas dataframes together

自古美人都是妖i 提交于 2019-11-27 17:55:42
I have a list of Pandas dataframes that I would like to combine into one Pandas dataframe. I am using Python 2.7.10 and Pandas 0.16.2 I created the list of dataframes from: import pandas as pd dfs = [] sqlall = "select * from mytable" for chunk in pd.read_sql_query(sqlall , cnxn, chunksize=10000): dfs.append(chunk) This returns a list of dataframes type(dfs[0]) Out[6]: pandas.core.frame.DataFrame type(dfs) Out[7]: list len(dfs) Out[8]: 408 Here is some sample data # sample dataframes d1 = pd.DataFrame({'one' : [1., 2., 3., 4.], 'two' : [4., 3., 2., 1.]}) d2 = pd.DataFrame({'one' : [5., 6., 7.,

How to concat two ArrayLists?

非 Y 不嫁゛ 提交于 2019-11-27 12:39:42
问题 I have two ArrayList s of equal size. List 1 consists of 10 names and list 2 consists of their phone numbers. I want to concat the names and number into one ArrayList . How do I do this? 回答1: You can use .addAll() to add the elements of the second list to the first: array1.addAll(array2); Edit: Based on your clarification above (" i want a single String in the new Arraylist which has both name and number. "), you would want to loop through the first list and append the item from the second