[英]How to eliminate first two numbers of a digit and how to get last 6 digits in mysql query?
我有一個表,該表具有以00******
或********
開頭的八位數字,如果數字以00
開頭,我必須消除00
並選擇其余的6位數字,如果數據沒有開頭是零,那么我必須選擇數據的前六位。 請讓我知道我該怎么做?
SELECT CASE WHEN SUBSTRING(Col,1,2)='00'
THEN SUBSTRING(Col,3,8)
ELSE SUBSTRING(Col,1,6)
END AS Col
FROM YOURTABLE;
假設它是一個名為the_column
的CHAR(8)
:
選擇IF(the_column REGEXP'^ 00',RIGHT(the_column,6),LEFT(the_column,6))AS x FROM some_table
+------------+
| the_column |
+------------+
| 00123456 |
| 87654321 |
+------------+
mysql> SELECT IF(the_column REGEXP '^00', RIGHT(the_column, 6), LEFT(the_column, 6)) x
FROM foo;
+--------+
| x |
+--------+
| 123456 |
| 876543 |
+--------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.