Chinaunix

标题: 急:字符串运算问题? [打印本页]

作者: 不倒翁(A)    时间: 2004-11-25 18:02
标题: 急:字符串运算问题?
有字符串字段:  上半场 2:3 下半场 1:0
问题: 全场=3:3
我有什么办法用'sql'语句计算出来呢?
求大哥大姐帮帮忙!先谢了
作者: odin_free    时间: 2004-11-26 09:11
标题: 急:字符串运算问题?
考虑用程序把 具体的东西光用sql 太累~
当然用正则是可能解决的
作者: welbird    时间: 2004-11-26 09:40
标题: 急:字符串运算问题?
实在不怎么想回答你的问题。
你的问题用编程来实现要好一点。
如果非要用sql,试一下一下的代码
其中 table 是你是表名,field 是你要处理的字段。
select
CONCAT(
cast(
cast(SUBSTRING(field,locate(':',field)-1,1) as unsigned)
+
cast(SUBSTRING(field,locate(':',field,10)-1,1) as unsigned)
as char)
,':::',
cast(
cast(SUBSTRING(field,locate(':',field)+1,1) as unsigned)
+
cast(SUBSTRING(field,locate(':',field,10)+1,1) as unsigned)
as char)
)
from table
作者: 不倒翁(A)    时间: 2004-11-26 09:50
标题: 急:字符串运算问题?
多谢楼上两位




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2