Показать сообщение отдельно

  #29  
Старый 25.03.2008, 11:24
krypt3r
Познавший АНТИЧАТ
Регистрация: 27.04.2007
Сообщений: 1,044
С нами: 10021597

Репутация: 905


По умолчанию

Если поле фиксированной длины, то можно попробовать вот так:
Код:
mysql> select * from test;
+-------+------+
| id    | link |
+-------+------+
| 12345 |    1 |
| 91311 |    2 |
| 12912 |    3 |
| 90122 |    4 |
| 64400 |    5 |
+-------+------+
5 rows in set (0.00 sec)

mysql> create temporary table testtest (link int, a1 int, a2 int, a3 int, a4 int, a5 int) select link, floor(id/10000) as a1, floor(id/1000)-floor(id/10000)*10 as a2, floor(id/100)-floor(id/1000)*10 as a3, floor(id/10)-floor(id/100)*10 as a4, mod(id,10) as a5 from test;
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from testtest;
+------+------+------+------+------+------+
| link | a1   | a2   | a3   | a4   | a5   |
+------+------+------+------+------+------+
|    1 |    1 |    2 |    3 |    4 |    5 |
|    2 |    9 |    1 |    3 |    1 |    1 |
|    3 |    1 |    2 |    9 |    1 |    2 |
|    4 |    9 |    0 |    1 |    2 |    2 |
|    5 |    6 |    4 |    4 |    0 |    0 |
+------+------+------+------+------+------+
5 rows in set (0.01 sec)

mysql> update testtest set a1=(case a1 when 1 then 7 when 2 then 4 when 3 then 5 else a1 end), a2=(case a2 when 1 then 7 when 2 then 4 when 3 then 5 else a2 end), a3=(case a3 when 1 then 7 when 2 then 4 when 3 then 5 else a3 end), a4=(case a4 when 1 then 7 when 2 then 4 when 3 then 5 else a4 end), a5=(case a5 when 1 then 7 when 2 then 4 when 3 then 5 else a5 end);
Query OK, 4 rows affected (0.00 sec)
Rows matched: 5  Changed: 4  Warnings: 0

mysql> update test t1 inner join testtest t2 using (link) set t1.id = t2.a1*10000+t2.a2*1000+t2.a3*100+t2.a4*10+t2.a5;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 5  Changed: 4  Warnings: 0

mysql> select * from test;
+-------+------+
| id    | link |
+-------+------+
| 74545 |    1 |
| 97577 |    2 |
| 74974 |    3 |
| 90744 |    4 |
| 64400 |    5 |
+-------+------+
5 rows in set (0.00 sec)
 
Ответить с цитированием