認爲你有三種情況:左0000-00-00
串,右和中間:
+------+------+--------------------------------+
| ID | Name | Return Date |
+------+------+--------------------------------+
| 1 | A | 0000-00-00,2016-02-1,2016-1-15 |
| 2 | B | 0000-00-00,2016-04-1 |
| 3 | C | 0000-00-00,2016-04-4 |
+------+------+--------------------------------+
使用REPLACE
功能:
SELECT `Return Date`, REPLACE(`Return Date`,'0000-00-00,','') as replaced
FROM YourTable;
+--------------------------------+----------------------+
| Return Date | replaced |
+--------------------------------+----------------------+
| 0000-00-00,2016-02-1,2016-1-15 | 2016-02-1,2016-1-15 |
| 0000-00-00,2016-04-1 | 2016-04-1 |
| 0000-00-00,2016-04-4 | 2016-04-4 |
+--------------------------------+----------------------+
你更新一句話是:
UPDATE YourTable
SET `Return Date` = REPLACE(`Return Date`,'0000-00-00,','')
WHERE `Return Date` like '%0000-00-00,%';
您必須對其他情況下,像'0000-00-00'
在中間或右側做類似的查詢。
他們是字符串。你使用標準的字符串操作/函數:http://dev.mysql.com/doc/refman/5.7/en/string-functions.html如果你的數據庫已經正確的標準化,你不需要問這個問題。它會是一個簡單的'delete .. .where date ='0000-00-00''查詢。 –
'SUBSTRING(\'Return Date \'FROM 11);' –
這裏真正的解決方案是不將多個值存儲在單個列中! –