I'm new in sql and couldn't found how to change just firts line in a cell.
This is value of cell.
[B]Ynt: Hello I'm Jack[/B]
2 lines
3 lines
4 lines
I want to change it to
2 lines
3 lines
4 lines
Could you please help me for queries? Every first rows begin with [B]Ynt: and ending with [/B] There is one blank line after firts line. Check below pisture.
UPDATE xf_post SET message = REPLACE(message, 'Ynt:%', '');
delete just first lines in a cell who has begin with "Ynt:"
try this but on sample.
you can make +3 as your need.
if you not understand let me know
UPDATE xf_post SET
message = REPLACE(message,SUBSTRING(message,1,POSITION( '[/b]' IN message)+3) , '')
where message like "[b]Ynt:%"
I have just replace the message ="your given text" it is working as your desire result check it
check below query
select REPLACE("[b]Ynt: 80'li yıllarda çocuk olmak..[/b] Yeğenim henüz dört yaşında.. [b][SIZE=16px]1990 lı olmakta böyleydi işte....[/SIZE][/b] 1980li yıllarda hayatının ilk tecrübelerini yaşamış, ilkokula gitmiş, Kenan Evren´i, Erdal İnönü´yü, Özal'ı tanımış olmak, Ajda Pekkan´ın Alo, Michael Jackson´ın Pepsi reklamlarını hatırlayacak kadar şanslı olmak demek.. [b]Türkiye'de yaşamış son mutlu kuşak olduğunu hüzünle hissetmek demek.. [/b] [b]Katılıyorum. 1990 lardada öyle[/b]",SUBSTRING("[b]Ynt: 80'li yıllarda çocuk olmak..[/b] Yeğenim henüz dört yaşında.. [b][SIZE=16px]1990 lı olmakta böyleydi işte....[/SIZE][/b] 1980li yıllarda hayatının ilk tecrübelerini yaşamış, ilkokula gitmiş, Kenan Evren´i, Erdal İnönü´yü, Özal'ı tanımış olmak, Ajda Pekkan´ın Alo, Michael Jackson´ın Pepsi reklamlarını hatırlayacak kadar şanslı olmak demek.. [b]Türkiye'de yaşamış son mutlu kuşak olduğunu hüzünle hissetmek demek.. [/b] [b]Katılıyorum. 1990 lardada öyle[/b]",1,POSITION( '[/b]' IN "[b]Ynt: 80'li yıllarda çocuk olmak..[/b] Yeğenim henüz dört yaşında.. [b][SIZE=16px]1990 lı olmakta böyleydi işte....[/SIZE][/b] 1980li yıllarda hayatının ilk tecrübelerini yaşamış, ilkokula gitmiş, Kenan Evren´i, Erdal İnönü´yü, Özal'ı tanımış olmak, Ajda Pekkan´ın Alo, Michael Jackson´ın Pepsi reklamlarını hatırlayacak kadar şanslı olmak demek.. [b]Türkiye'de yaşamış son mutlu kuşak olduğunu hüzünle hissetmek demek.. [/b] [b]Katılıyorum. 1990 lardada öyle[/b]")+3) , '')
Related
Using SQL, I want to search for and retrieve sub-strings that are preceded by a known sub-string "XX." and ending in a " " or "'".
For example if I start with CONTOOOH 788 XX. 3C, MNOP I need to extract value 3C
I've tried with substring(input, posisiton, len) but not sure about criteria of len since the len are vary.
select substring(input, position("XX." in input)+4, **???**)
from tables
where input like '%XX.%';
I am using MySQL.
Input
CONTOH LALALA 12 XX. 1 ABCD LALA NANA MAMA KAKA
CONTOH NANANANA 34 XX. 02 EFGH IJKL MN
CONTOOOH MAMAMA XX. 1A IJKL YOYO
CONTOOOH NANA XIXI 788 XX. 423C, MNOP QRSTU ASDF POIU
EXAMPLE BLA BLA HOHOHO 910 XX. A4, QRST ASDGHH
EXAMPLE ZZZ AAA BBB 1112 XX. BB5, UVWXASDGHH
Output
1
02
1A
423C
A4
BB5
One option uses SUBSTRING_INDEX with REPLACE:
SELECT
Input,
REPLACE(SUBSTRING_INDEX(
SUBSTRING_INDEX(Input, 'XX. ', -1), ' ', 1), ',', '') AS Output
FROM yourTable;
Demo
Here is how the string operations are working, step by step
CONTOOOH 788 XX. 3C, MNOP - initial input
3C, MNOP - after first call to SUBSTRING_INDEX
3C, - after second call to SUBSTRING_INDEX
3C - after call to REPLACE, to remove the comma
According to the documentation for MySQL substring
length Optional. The forms without a len argument return a substring from string str starting at position pos.
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring
Thus if your current code works to your liking except for length, simply omit it, and it will return the entire substring.
I want to replace every instance of a particular character in a string by another, 's' & '#' in this case
So, San Jose becomes #an Jo#e
I am using the following queries:
UPDATE city SET NewName = REPLACE(Name,'s','#') WHERE(ID<5000);
UPDATE city SET NewName = REPLACE(Name,'S','#') WHERE(ID<5000);
SELECT * FROM city WHERE Name LIKE "%s%" OR "%S%";
This is what the table looks like:
ID Name CountryCode District Population NewName
4 Mazar-e-Sharif AFG Balkh 127800 Mazar-e-#harif
5 Amsterdam NLD Noord-Holland 731200 Amsterdam
15 Enschede NLD Overijssel 149544 Enschede
19 Zaanstad NLD Noord-Holland 135621 Zaanstad
20 ´s-Hertogenbosch NLD Noord-Brabant 129170 ´s-Hertogenbosch
21 Amersfoort NLD Utrecht 126270 Amersfoort
22 Maastricht NLD Limburg 122087 Maastricht
33 Willemstad ANT Curaçao 2345 Willemstad
I am using this database. I have also added a new column to the table, NewName
Do this in one step:
UPDATE city
SET NewName = REPLACE(REPLACE(Name, 's', '#'), 'S', '#')
WHERE(ID < 5000);
Actually, the first will do if the collation for the column is case-insensitive.
Try to use next approach:
UPDATE city SET NewName = REGEXP_REPLACE(Name, '/[s]/ig', '#') WHERE(ID<5000);
OR update your request
UPDATE city SET NewName = REPLACE(REPLACE(Name,'s','#'),'S','#') WHERE(ID<5000);
A HTML table body has 1 column more than defined within the table header. This leads to skipping the last column and of course, column mismatch. How can I add the additional column to the result data.frame/table in R while reading in the HTML table with package("htmltab") Obviously, post processing does not help.
Here is an example:
code
install.packages("htmltab")
library(htmltab)
bu<- 0
bu <- data.table("Pl.", "Mannschaft", "Kurzname" , "Spiele", "G.", "U.", "V.", "Tore", "Diff.", "Pkt.")
#https://www.bundesliga-prognose.de/1/2009/1/
url <- "https://www.bundesliga-prognose.de/1/2009/1/"
bu <- htmltab(doc = url, column=10,columnnames=c ("Pl." , "Mannschaft", "Kurzname" , "Spiele", "G.", "U.", "V.", "Tore", "Diff.", "Pkt."), which = "//th[text() = 'Pl.']/ancestor::table")
bu <- data.table(bu)
head(bu)
This results in
Pl. Mannschaft Spiele G. U. V. Tore Diff. Pkt.
1: 1. VfL Wolfsburg Wolfsburg 1 1 0 0 2:0 2
2: 2. Eintracht Frankfurt E. Frankfurt 1 1 0 0 3:2 1
3: 3. FC Schalke 04 FC Schalke 04 1 1 0 0 2:1 1
4: 4. Borussia Dortmund B. Dortmund 1 1 0 0 1:0 1
5: NA Hertha BSC Berlin H. BSC Berlin 1 1 0 0 1:0 1
6: 6. Bor. Mönchengladbach M´gladbach 1 0 1 0 3:3 0
As the short-name("Kurzname") is not specified in the header the short-name ("Kurzname") is displayed with the games (Spiele) column an so on. So the last column is skipped. How can I add the additional column short-name ("Kurzname") while reading the header using the htmltab package?
In addition I would like to replace the NA in row 5 with the row-id/number using the htmltab package?
This seems to be indeed a problem for htmltab. The only solution i have found is to directly read the tbody of the table. You would then need to add the header manually.
htmltab(doc = url, which = "//table[2]/tbody")
With that help I found a quite simple solution:
specify to skip the header
List/define all colums thru colNames
url <- "https://www.bundesliga-prognose.de/1/2007/5/"
sp_2007_5<- htmltab(doc = url, which = "//table[1]/tbody", header = 0 , colNames = c("Datum" , "Anpfiff", "Heim" , "Heim_Kurzname","Gast", "Gast_Kurzname","Ergebnis", "Prognose"), rm_nodata_cols = F,encoding = "UTF-8")
head(sp_2007_5)
I have data in csv format as shown below.
The data has the below format
"first_name","last_name","company_name","address","city","county","postal","phone1","phone2","email","web"
The sample data named under User.csv. The file contains below data.
"Aleshia","Tomkiewicz","Alan D Rosenburg Cpa Pc","14, Taylor St","St. Stephens Ward","Kent","CT2 7PP","01835-703597","01944-369967","atomkiewicz#hotmail.com","http://www.alandrosenburgcpapc.co.uk"
"Evan","Zigomalas","Cap Gemini America","5, Binney St","Abbey Ward","Buckinghamshire","HP11 2AX","01937-864715","01714-737668","evan.zigomalas#gmail.com","http://www.capgeminiamerica.co.uk"
"France","Andrade","Elliott, John W Esq","8 Moor Place","East Southbourne and Tuckton W","Bournemouth","BH6 3BE","01347-368222","01935-821636","france.andrade#hotmail.com","http://www.elliottjohnwesq.co.uk"
When I try the same to load using PigStorage
user = LOAD '/home/abhijit/Downloads/User.csv' USING PigStorage(',');
DUMP user;
The output of it is like :
("Aleshia","Tomkiewicz","Alan D Rosenburg Cpa Pc","14 Taylor St","St. Stephens Ward","Kent","CT2 7PP","01835-703597","01944-369967","atomkiewicz#hotmail.com","http://www.alandrosenburgcpapc.co.uk")
("Evan","Zigomalas","Cap Gemini America","5, Binney St","Abbey Ward","Buckinghamshire","HP11 2AX","01937-864715","01714-737668","evan.zigomalas#gmail.com","http://www.capgeminiamerica.co.uk")
("France","Andrade","Elliott, John W Esq","8 Moor Place","East Southbourne and Tuckton W","Bournemouth","BH6 3BE","01347-368222","01935-821636","france.andrade#hotmail.com","http://www.elliottjohnwesq.co.uk")
I want to do a group by on city. So I have written
grp = group user by $4;
dump grp;
I get the output as :
( Binney St",{("Evan","Zigomalas","Cap Gemini America","5, Binney St","Abbey Ward","Buckinghamshire","HP11 2AX","01937-864715","01714-737668","evan.zigomalas#gmail.com","http://www.capgeminiamerica.co.uk")})
("8 Moor Place",{("France","Andrade","Elliott, John W Esq","8 Moor Place","East Southbourne and Tuckton W","Bournemouth","BH6 3BE","01347-368222","01935-821636","france.andrade#hotmail.com","http://www.elliottjohnwesq.co.uk")})
("St. Stephens Ward",{("Aleshia","Tomkiewicz","Alan D Rosenburg Cpa Pc","14 Taylor St","St. Stephens Ward","Kent","CT2 7PP","01835-703597","01944-369967","atomkiewicz#hotmail.com","http://www.alandrosenburgcpapc.co.uk")})
The company_name and address is creating a problem as it contains ',' as part of it. for example "14, Taylor St" in address or "Elliott, John W Esq" in company_name.
so my $4 is treated for "Taylor St" and not the "St. Stephens Ward"
So because of the extra delimiter in the address data or the company_name data is not loaded properly or seperated properly and the group by fuction is not giving correct result.
How can I achieve the group by output as below
("Abbey Ward",{("Evan","Zigomalas","Cap Gemini America","5, Binney St","Abbey Ward","Buckinghamshire","HP11 2AX","01937-864715","01714-737668","evan.zigomalas#gmail.com","http://www.capgeminiamerica.co.uk")})
("St. Stephens Ward",{("Aleshia","Tomkiewicz","Alan D Rosenburg Cpa Pc","14, Taylor St","St. Stephens Ward","Kent","CT2 7PP","01835-703597","01944-369967","atomkiewicz#hotmail.com","http://www.alandrosenburgcpapc.co.uk")})
("East Southbourne and Tuckton W",{("France","Andrade","Elliott, John W Esq","8 Moor Place","East Southbourne and Tuckton W","Bournemouth","BH6 3BE","01347-368222","01935-821636","france.andrade#hotmail.com","http://www.elliottjohnwesq.co.uk")})
grp = group a by $5 ;
It won't be the solution for me. I already thought of it.
The problem is that PigStorage does not take escaping into account, so creates columns for fields that should not be columns (each time an entry contains a comma).
Using CSVExcelStorage will solve this as this storage can deal with escaping, thus creating the right amount and sequence of columns.
I have a list (mysql table) of People and their titles as shown in the table below. I also have a list of titles and their categories. How do I assign their categories to the person? The problem arises when there are multiple titles for a person. What is the pythonic way of mapping the title to the category and assigning it to the person?
People Table
Name Title
--------------------
John D CEO, COO, CTO
Mary J COO, MD
Tim C Dev Ops, Director
Title Category table
Title Executive IT Other
-----------------------------
CEO 1
COO 1
CTO 1 1
MD 1
Dev Ops 1
Director 1
Desired output :
Name Title Executive IT Other
---------------------------------------------
John D CEO, COO, CTO 1 1
Mary J COO, MD 1
Tim C Dev Ops, Director 1 1
name_title = (("John D",("CEO","COO","CTO")),
("Mary J",("COO","MD")),
("Tim C",("Dev Ops","Director")))
title_cat = {"CEO": set(["Executive"]),
"COO": set(["Executive"]),
"CTO": set(["Executive"]),
"MD": set(["Executive"]),
"Dev Ops": set(["IT"]),
"Director": set(["Other"])}
name_cat = [(name, reduce(lambda x,y:x|y, [title_cat[title]for title in titles])) for name,titles in name_title]
It would be nice if there was a union which behaved like sum on sets.
people=['john','Mary','Tim']
Title=[['CEO','COO','CTO'],['COO','MD'],['DevOps','Director']]
title_des={'CEO':'Executive','COO':'Executive','CTO':'Executive',
'MD':'Executive','DevOps':'IT','Director':'Others'
}
people_des={}
for i,x in enumerate(people):
people_des[x]={}
for y in Title[i]:
if title_des[y] not in people_des[x]:
people_des[x][title_des[y]]=[y]
else:
people_des[x][title_des[y]].append(y)
print(people_des)
output:
{'Tim': {'IT': ['DevOps'], 'Others': ['Director']}, 'john': {'Executive': ['CEO', 'COO', 'CTO']}, 'Mary': {'Executive': ['COO', 'MD']}}
Start by arranging your input data in a dictionary-of-lists form:
>>> name_to_titles = {
'John D': ['CEO', 'COO', 'CTO'],
'Mary J': ['COO', 'MD'],
'Tim C': ['Dev Ops', 'Director']
}
Then loop over the input dictionary to create the reverse mapping:
>>> title_to_names = {}
>>> for name, titles in name_to_titles.items():
for title in titles:
title_to_names.setdefault(title, []).append(name)
>>> import pprint
>>> pprint.pprint(title_to_names)
{'CEO': ['John D'],
'COO': ['John D', 'Mary J'],
'CTO': ['John D'],
'Dev Ops': ['Tim C'],
'Director': ['Tim C'],
'MD': ['Mary J']}
I propose this if you mean you have the string:
s = '''Name Title
--------------------
John D CEO, COO, CTO
Mary J COO, MD
Tim C Dev Ops, Director
Title Executive IT Other
-----------------------------
CEO 1
COO 1
CTO 1
MD 1
Dev Ops 1
Director 1
'''
lines = s.split('\n')
it = iter(lines)
for line in it:
if line.startswith('Name'):
break
next(it) # '--------------------'
for line in it:
if not line:
break
split = line.split()
titles = split[2:]
name = split[:2]
print ' '.join(name), titles
# John D ['CEO,', 'COO,', 'CTO']
# Mary J ['COO,', 'MD']
# Tim C ['Dev', 'Ops,', 'Director']