I have a table x with the below fields,
n_i int(10) NOT NULL,
n_m longtext,
n_t varchar(255) DEFAULT NULL,
n_s varchar(50) DEFAULT NULL,
n_c int(10) DEFAULT NULL,
n_d datetime DEFAULT NULL
Data:
1, ABC has kept Hold rating on John Inc for target of $ 125 over a 12 month horizon from the current market price of $ 101., Hold John Inc for target of $ 125: ABC, ABC PCG, 1, 1/27/2006 22:55
2, RB Research has kept Buy rating on Johnson (New York) Inc for target of $ 80 over a 12 month horizon from the current market price of $ 64., Buy Johnson (New York) Inc for target of $ 80: RB Research, RB Research, 1, 1/27/2006 23:03
3, XYZ Research has kept Buy rating on John & John Manufacturing (USA) Inc, a subsidiary of John & John Inc for target of $ 340 from the current market price of $ 270., Buy John & John Manufacturing (USA) Inc for target of Rs.340: XYZ Research, XYZ Research, 1, 1/27/2006 23:06
4, ABCDE Research has upgraded Johnson (New York) Inc to Buy with a target of $ 1000 from the current market price of $ 750., Buy Johnson (New York) Inc for target of $ 1000: ABCDE Research, ABCDE Research, 1, 1/27/2006 23:10
5, JKL Private Client Research has kept Buy rating on John2 Inc, parent company of John & John Manufacturing (USA) Inc with a target price of $ 295 from the current market price of $ 276., Buy John2 Inc for target of $ 295: JKL Private Client Research, JKL Private CLient Research, 1, 1/27/2006 23:12
I would like to create the below table y with data from above table plus a new field n_sy. The search criteria is a string say, BSSN which will be taken from table z and searched in fields n_t and n_m of table x and if found field n_sy in table y would be updated with corresponding field data "BSIS" from table z. Also, the field "n_sy" should be able to hold more than one value. :-(
n_i int(10) NOT NULL,
n_m longtext,
n_t varchar(255) DEFAULT NULL,
n_s varchar(50) DEFAULT NULL,
n_c int(10) DEFAULT NULL,
n_d datetime DEFAULT NULL,
n_sy text NOT NULL
Data:
1, ABC has kept Hold rating on John Inc for target of $ 125 over a 12 month horizon from the current market price of $ 101., Hold John Inc for target of $ 125: ABC, ABC PCG, 1, 1/27/2006 22:55, ABCD12345J
2, RB Research has kept Buy rating on Johnson (New York) Inc for target of $ 80 over a 12 month horizon from the current market price of $ 64., Buy Johnson (New York) Inc for target of $ 80: RB Research, RB Research, 1, 1/27/2006 23:03, ABCD34567L
3, XYZ Research has kept Buy rating on John & John Manufacturing (USA) Inc, a subsidiary of John & John Inc for target of $ 340 from the current market price of $ 270., Buy John & John Manufacturing (USA) Inc for target of Rs.340: XYZ Research, XYZ Research, 1, 1/27/2006 23:06, "ABCD56789A, ABCD45678M"
4, ABCDE Research has upgraded Johnson (New York) Inc to Buy with a target of $ 1000 from the current market price of $ 750., Buy Johnson (New York) Inc for target of $ 1000: ABCDE Research, ABCDE Research, 1, 1/27/2006 23:10, ABCD34567L
5, JKL Private Client Research has kept Buy rating on John2 Inc, parent company of Johnson (New York) Inc with a target price of $ 295 from the current market price of $ 276., Buy John2 Inc for target of $ 295: JKL Private Client Research, JKL Private CLient Research, 1, 1/27/2006 23:12, "ABCD23456K, ABCD34567L"
Table z
`BSCe` double DEFAULT NULL,
`BSSI` text,
`BSSN` text,
`BSSt` text,
`BSGr` text,
`BSFV` int(11) DEFAULT NULL,
`BSIS` text,
`BSIn` text,
`BSInst` text,
`NSSy` text,
`NSSc` text,
`NSSer` text,
`NSDOL` text,
`NSPUV` int(4) DEFAULT NULL,
`NSMktL` int(3) DEFAULT NULL,
`NSIS` text,
`NSEFV` int(11) DEFAULT NULL
12345, ABCD, John Inc, A, B, 10, ABCD12345J, Mine, E, J12345, John, T, 10-Oct-2019, 10, 1, ABCD12345J, 10
12346, XYZ, John2 Inc, A, B, 10, ABCD23456K, Iron, E, J12346, John2, T, 11-Jan-2020, 10, 1, ABCD23456K, 10
12347, JKL, Johnson (New York) Inc, A, B, 10, ABCD34567L, Electricty, E, J12347, John3, T, 7-Dec-2019, 10, 1, ABCD34567L, 10
12348, IJK, John & John Inc, A, B, 10, ABCD45678M, Mine, E, J12348, John & John, T, 19-Apr-2019, 10, 1, ABCD45678M, 10
12349, EFGH, John & John Manufacturing (USA) Inc, A, B, 10, ABCD56789A, IT, E, J12349, John & John Manufacturing Inc, T, 29-May-2019, 10, 1, ABCD56789A, 10
Looking for your help, as the MYSQL table is fairly large.
Use below query,
Creates the table with structure of x
create table y as select * from table x;
Adds column column n_sy
alter table y add n_sy text NOT NULL;
Updates BSSN from z to n_sy in y
update y
inner join z
on (z.BSSN = y.n_t)
set y.n_sy = z.BSIS;
Updates BSSN from z to n_sy in y to hold more than one value
update y
inner join z
on (z.BSSN = y.n_m)
set y.n_sy = y.n_sy || ',' || z.BSIS;
Would appreciate any help on this problem
In MS Access
I'd like to split the values of one field (Main Address) to 2 separate fields (Address 1 and Address 2) where in Address 1 gets the first line and then Address 2 gets the second and other line items
ex #1
Main Address | Address 1 | Address 2
----------------------------------------
1 Main Road | 1 Main Road | San Jose CA
San Jose CA
ex #2
Main Address | Address 1 | Address 2
----------------------------------------
1 Main Road | 1 Main Road | San Jose CA Drop at Front
San Jose CA
Drop at Front
Thanks All!
Hope the representation of the samples makes sense, if not let me know if you have questions and I'll clarify! TA
Does the [Main Address] data have Cr and Lf characters to force new lines? If it doesn't, what you want is virtually impossible. If yes, an expression in query or textbox:
Replace(Left([Main Address] & "", Instr([Main Address] & Chr(13), Chr(13))), Chr(13), "")
Trim(Replace(Mid([Main Address] & "", Instr([Main Address] & Chr(13), Chr(13))), Chr(13) & Chr(10), " "))
I write this code in scala.html to show the MySQL data in an HTML table:
#for(a <- 1 to rowNum){
#rs.next()
<tr>
<td>#rs.getString("building_id")</td>
<td>#rs.getString("building_name")</td>
<td>#rs.getString("building_type")</td>
<td>#rs.getString("address")</td>
</tr>
It gives the following result:
true true true true true true true true true true
id name type address
1 The Floravale condo Westwood Avenue
2 building2 condo Jurong West Street 21
3 building3 hdb Jurong West Street 31
4 building4 hdb Jurong West Street 81
5 building5 hdb Jurong West Street 61
6 building6 hdb Jurong West Street 81
7 building7 hdb Kang Ching Road
8 building8 hdb Kang Ching Road
9 building9 hdb Boon Lay Drive
10 building10 hdb Boon Lay Place
How can I hide the true as the output of #rs.next()?
Or are there other ways to display data? Thanks!
As commented, it is probably that true is being returned, and therefore appearing as a result. A more typical usage would be to collect your rows in a List passed to the view, often in it's own case class (say Building), then use a map:
#buildings.map { building =>
<td>building.id</td>
<td>building.name</td>
...
}
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']