concat

MySQL select with CONCAT condition

*爱你&永不变心* 提交于 2019-11-26 04:42:45
问题 I\'m trying to compile this in my mind.. i have a table with firstname and lastname fields and i have a string like \"Bob Jones\" or \"Bob Michael Jones\" and several others. the thing is, i have for example Bob in firstname, and Michael Jones in lastname so i\'m trying to SELECT neededfield, CONCAT(firstname, \' \', lastname) as firstlast FROM users WHERE firstlast = \"Bob Michael Jones\" but it says unknown column \"firstlast\".. can anyone help please ? 回答1: The aliases you give are for

Why does Java's concat() method not do anything?

只谈情不闲聊 提交于 2019-11-26 04:00:31
问题 This code: String s = \"TEST\"; String s2 = s.trim(); s.concat(\"ING\"); System.out.println(\"S = \"+s); System.out.println(\"S2 = \"+s2); results in this output: S = TEST S2 = TEST BUILD SUCCESSFUL (total time: 0 seconds) Why are \"TEST\" and \"ING\" not concatenated together? 回答1: a String is immutable, meaning you cannot change a String in Java. concat() returns a new, concatenated, string. String s = "TEST"; String s2 = s.trim(); String s3 = s.concat("ING"); System.out.println("S = "+s);

Using pandas .append within for loop

淺唱寂寞╮ 提交于 2019-11-26 03:57:25
问题 I am appending rows to a pandas DataFrame within a for loop, but at the end the dataframe is always empty. I don\'t want to add the rows to an array and then call the DataFrame constructer, because my actual for loop handles lots of data. I also tried pd.concat without success. Could anyone highlight what I am missing to make the append statement work? Here\'s a dummy example: import pandas as pd import numpy as np data = pd.DataFrame([]) for i in np.arange(0, 4): if i % 2 == 0: data.append

String concatenation in MySQL

本小妞迷上赌 提交于 2019-11-26 02:20:41
问题 I am using MySQL and MySQL Workbench 5.2 CE. When I try to concatenate 2 columns, last_name and first_name , it doesn\'t work : select first_name + last_name as \"Name\" from test.student 回答1: MySQL is different from most DBMSs use of + or || for concatenation. It uses the CONCAT function: SELECT CONCAT(first_name, " ", last_name) AS Name FROM test.student As @eggyal pointed out in comments, you can enable string concatenation with the || operator in MySQL by setting the PIPES_AS_CONCAT SQL

How to use GROUP_CONCAT in a CONCAT in MySQL

喜欢而已 提交于 2019-11-26 01:28:43
问题 If I have a table with the following data in MySQL: id Name Value 1 A 4 1 A 5 1 B 8 2 C 9 how do I get it into the following format? id Column 1 A:4,5,B:8 2 C:9 I think I have to use GROUP_CONCAT . But I\'m not sure how it works. 回答1: select id, group_concat(`Name` separator ',') as `ColumnName` from ( select id, concat(`Name`, ':', group_concat(`Value` separator ',')) as `Name` from mytbl group by id, `Name` ) tbl group by id; You can see it implemented here : Sql Fiddle Demo. Exactly what

Which is the preferred way to concatenate a string in Python?

安稳与你 提交于 2019-11-25 23:52:34
问题 Since Python\'s string can\'t be changed, I was wondering how to concatenate a string more efficiently? I can write like it: s += stringfromelsewhere or like this: s = [] s.append(somestring) later s = \'\'.join(s) While writing this question, I found a good article talking about the topic. http://www.skymind.com/~ocrow/python_string/ But it\'s in Python 2.x., so the question would be did something change in Python 3? 回答1: The best way of appending a string to a string variable is to use + or

How to concatenate string variables in Bash

独自空忆成欢 提交于 2019-11-25 22:40:21
问题 In PHP, strings are concatenated together as follows: $foo = \"Hello\"; $foo .= \" World\"; Here, $foo becomes \"Hello World\". How is this accomplished in Bash? 回答1: foo="Hello" foo="${foo} World" echo "${foo}" > Hello World In general to concatenate two variables you can just write them one after another: a='Hello' b='World' c="${a} ${b}" echo "${c}" > Hello World 回答2: Bash also supports a += operator as shown in this code: $ A="X Y" $ A+=" Z" $ echo "$A" X Y Z 回答3: Bash first As this

Can I concatenate multiple MySQL rows into one field?

余生颓废 提交于 2019-11-25 21:37:50
问题 Using MySQL , I can do something like: SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; My Output: shopping fishing coding but instead I just want 1 row, 1 col: Expected Output: shopping, fishing, coding The reason is that I\'m selecting multiple values from multiple tables, and after all the joins I\'ve got a lot more rows than I\'d like. I\'ve looked for a function on MySQL Doc and it doesn\'t look like the CONCAT or CONCAT_WS functions accept result sets, so does anyone here know