MYSQL 请教一个语句怎么写

ci__ci 2010-10-25 10:41:19
MYSQL

在一个表里。一字段是记录商品价格的。

由于当时没统一录入数据格式。导致有如下几种数据

10。35万元

25。68万

35。00

以市场价为准

以上四种格式。。其中可能还会有标点或者空格在其后面

现在需要按价格排序。有没有SQL语句可以实现。

或者在该表新建一个字段。

通过正则把那字段里的数字取出来。中文的(以市场价为准)则转为0

UPDATE到新建的字段里

请教高手了 感谢
...全文
95 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ci__ci 2010-10-25
  • 打赏
  • 举报
回复
FUNCTION db_.ISNUMERIC does not exist
dawugui 2010-10-25
  • 打赏
  • 举报
回复
col                  newcol               
-------------------- --------------------
以市场价为准 .00
10。35万元 10.35
25。68万 25.68
35。00 35.00

(所影响的行数为 4 行)

至于单位就很难说了.
dawugui 2010-10-25
  • 打赏
  • 举报
回复
create table tb(col varchar(20))
insert into tb values('10。35万元')
insert into tb values('25。68万')
insert into tb values('35。00')
insert into tb values('以市场价为准')
go

select col ,
newcol = case when ISNUMERIC(replace(replace(replace(col,'万',''),'元',''),'。','')) = 0 then 0 else cast(replace(replace(replace(col,'万',''),'元',''),'。','') as decimal(18,2)) end
from tb order by newcol

drop table tb

/*
col newcol
-------------------- --------------------
以市场价为准 .00
10。35万元 1035.00
25。68万 2568.00
35。00 3500.00

(所影响的行数为 4 行)

*/
dawugui 2010-10-25
  • 打赏
  • 举报
回复
select * from tb where ISNUMERIC(replace(replace(replace(col,'万',''),'元',''),'。','')) = 1
fpzgm 2010-10-25
  • 打赏
  • 举报
回复

create table tb(col varchar(20))
insert into tb values('10。万元')
insert into tb values('25。万')
insert into tb values('35。')
insert into tb values('以市场价为准')
go



select col,
case when col='以市场价为准' then 0
else (cast( (left(col,charindex('。',col)-1)+'.'+
substring(col,charindex('。',col)+1,2))
as decimal(10,2))*
(case when charindex('万',col)>0 then 10000 else 1 end))
end as col1
from tb order by col1 desc

/*
col col1
25。68万 256800.00
10。35万元 103500.00
35。00 35.00
以市场价为准 0.00




*/

fpzgm 2010-10-25
  • 打赏
  • 举报
回复

select col,
case when (col regexp '^[0-9]*$')=1 then
(cast( (left(col,charindex('。',col)-1)+'.'+
substring(col,charindex('。',col)+1,2))
as demical(10,2))*
(case when charindex('万',col)>0 then 10000 else 1 end))
else 0 end as col
from [table]
abuying 2010-10-25
  • 打赏
  • 举报
回复
--mysql只能使用if
select col ,
if(col='以市场价为准','0', replace(replace(replace(col,'万',''),'元',''),'。','')) as newcol
from tb order by newcol
abuying 2010-10-25
  • 打赏
  • 举报
回复

--mysql没有isnumber函数
select col ,
newcol = case when col='以市场价为准' then '0' else replace(replace(replace(col,'万','0000'),'元',''),'。','') end
from tb order by newcol

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧