![](/img/trans.png)
[英]How to split or get the value in column and update in another column in same table? php mysql
[英]How to get the value in field by new line and update into the column in table with same id in php mysql?
我想問問如何獲取該列的值並更新為具有相同ID的另一列..此數據來自電子郵件管道,我想分離正文的值並更新為費用,凈額和毛額字段。
我希望你能幫助我。.謝謝
+------+---------+--------------------+---------+----------+-------+----------+
| id | subject | body | expense | net | gross | email |
+------+---------+--------------------+---------+----------+-------+----------+
| 1 | Sales | Expense = 2000 | 0 | 0 | 0 | ex@ex.com|
| | | netIncome = 5000 | | | | |
| | | Gross = 10000 | | | | |
+------+---------+--------------------+---------+----------+-------+----------+
假設您有一個\\n
換行符,並且body
具有相同的樣式,那么我們可以得到以下內容
mysql> select * from test \G
*************************** 1. row ***************************
id: 1
body: Expense = 2000
netIncome = 5000
Gross = 10000
現在要獲取每個金額,我們可以使用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 |
+---------+-----------+--------+
所以對於更新它可能是
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.