[英]How to get the value in field by new line and update into the column in table with same id in php mysql?
i want to ask how to get the value of the column and update into another column with same id.. this data came from email piping and i want to separate the value of the body and update into the expense , net and gross field.. 我想问问如何获取该列的值并更新为具有相同ID的另一列..此数据来自电子邮件管道,我想分离正文的值并更新为费用,净额和毛额字段。
i hope you can help me guys.. thank you 我希望你能帮助我。.谢谢
+------+---------+--------------------+---------+----------+-------+----------+
| id | subject | body | expense | net | gross | email |
+------+---------+--------------------+---------+----------+-------+----------+
| 1 | Sales | Expense = 2000 | 0 | 0 | 0 | ex@ex.com|
| | | netIncome = 5000 | | | | |
| | | Gross = 10000 | | | | |
+------+---------+--------------------+---------+----------+-------+----------+
Assuming that you have one \\n
for the line break and having the same pattern for the body
, lets say we have the following 假设您有一个
\\n
换行符,并且body
具有相同的样式,那么我们可以得到以下内容
mysql> select * from test \G
*************************** 1. row ***************************
id: 1
body: Expense = 2000
netIncome = 5000
Gross = 10000
Now to get each amount we can use substring_index
something as 现在要获取每个金额,我们可以使用
substring_index
作为
mysql> select
substring_index(substring_index(body,'=',-3),'\n',1) as expense,
substring_index(substring_index(body,'=',-2),'\n',1) as netincome,
substring_index(body,'=',-1) as gross from test;
+---------+-----------+--------+
| expense | netincome | gross |
+---------+-----------+--------+
| 2000 | 5000 | 10000 |
+---------+-----------+--------+
So for the update it could be as 所以对于更新它可能是
update your_table
set
expense = substring_index(substring_index(body,'=',-3),'\n',1),
net = substring_index(substring_index(body,'=',-2),'\n',1),
gross = substring_index(body,'=',-1) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.