Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

php - MySql - Concatenate/merge multiple columns into one column with hard codded titles

i should migrate multiple columns of text into one column (in another database). Now i know that it sounds complicated, but i will try my best to explain it. There is a table in mysql database called "products_desriptions". In that table we have columns like: descriptionDosage, descriptionAction, descriptionIndications and so on. What i want to do is to merge these columns into one column called "productDescription". Here is an example of what i have done:

SELECT 
   CONCAT_WS('
test', action, Indications, staff, dosage) AS productDescription)
FROM 
   products_descriptions
WHERE 
   product_id = 123

So the the columns are being merged successfully. The problem is that for each column there is a title in the frontpage, which is not being stored into the respective column. For example in the "dosage" column we have text like: "2xday, 14xweek" and so on. And on the frontpage what you can see is something like: "DOSAGE: 2xday, 14xweek" and so on. So for each column there is a hard codded title like this one, which i don't know how to get. I mean what i want to do is: to merge columns and respectively for each column i want a title to the respective text. I am working on php, so maybe it is not possible to be done only by mysql. Maybe i have to do it with php, but has anyone got any idea what exactly should i do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use concat function.

SELECT 
   CONCAT('
test', action, '
Indictions:', Indications,'
staff:', staff,'
dosage:', dosage) AS productDescription
FROM 
   products_descriptions
WHERE 
   product_id = 123

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...