您好,欢迎访问一九零五行业门户网

mysql 如何改正?

select (select replace('500x1x10','x','*') as a)/5000; 这个结果得到0.1,但是实际应该是1,怎么去改正?
回复讨论(解决方案) 字符串形态的表达式是不会被运算的
mysql 并没有类似 eval 的函数,或许你可以自己写一个
对于你的这个例子,可以写作
select substring_index(a,'*',1) * substring_index(substring_index(a,'*',2),'*',-1) * substring_index(substring_index(a,'*',3),'*',-1)
from (select replace('500x1x10','x','*') as a) t
但不具备普遍意义
如果mysql字段存储500x1x10字符串,但是计算的时候我需要将x替换成*,才可以进行计算。
可以查询出来了用php计算就简单多了
select process.fid,sum(case when (product.box_product_dimensions/5000)>box_shipping_weight then product.box_product_dimensions/5000 else box_shipping_weight end ) as sumweight, (case when (product.box_product_dimensions/5000)>box_shipping_weight then product.box_product_dimensions/5000 else box_shipping_weight end ) as weight from `process` left join product on product.pid=process.pid where 1 and process.receiver_id>0 and statu=3 and property=转仓单 and isover=n group by fid
这是我sql当中其中一段sql,贴出来给你看下。如果计算拿到程序里面,就不是很方便。
product.box_product_dimensions 存储的是字符串,形如:14x12x36 需要计算的话,替换改成14*12*36
你#4的代码与你主贴的问题根本就不是一回事
你#4的代码与你主贴的问题根本就不是一回事
select process.sku,process.fid,sum(case when (replace(product.box_product_dimensions,'x','*')/5000)>box_shipping_weight then product.box_product_dimensions/5000 else box_shipping_weight end ) as sumweight,
(case when (replace(product.box_product_dimensions,'x','*')/5000)>box_shipping_weight then product.box_product_dimensions/5000 else box_shipping_weight end ) as weight from `process`
left join product on product.pid=process.pid where 1 and process.receiver_id>0 and statu=3 and property=转仓单 and isover=n group by fid
product.box_product_dimensions 存储的是字符串,形如:14x12x36
那我#1已经明确的告诉你了,除非你自己写一个函数,否则是不可能指行字符串中的表达式的
那我#1已经明确的告诉你了,除非你自己写一个函数,否则是不可能指行字符串中的表达式的
select process.sku,process.comment2,sum(case when (select (select substring_index(box_product_dimensions,'x',1))*(select substring_index(substring_index(box_product_dimensions,'x',2),'x',-1))*(select substring_index(box_product_dimensions,'x',-1))/5000)>box_shipping_weight then (select (select substring_index(box_product_dimensions,'x',1))*(select substring_index(substring_index(box_product_dimensions,'x',2),'x',-1))*(select substring_index(box_product_dimensions,'x',-1))/5000)else box_shipping_weight end ) as sumweight, (case when (select (select substring_index(box_product_dimensions,'x',1))*(select substring_index(substring_index(box_product_dimensions,'x',2),'x',-1))*(select substring_index(box_product_dimensions,'x',-1))/5000)>box_shipping_weight then (select (select substring_index(box_product_dimensions,'x',1))*(select substring_index(substring_index(box_product_dimensions,'x',2),'x',-1))*(select substring_index(box_product_dimensions,'x',-1))/5000) else box_shipping_weight end ) as weight from `process` left join product on product.pid=process.pid where 1 and process.receiver_id>0 and statu=3 and property=转仓单 and isover=n group by comment2
( select substring_index(box_product_dimensions,'x',1))???
为什么要 select ??
( select substring_index(box_product_dimensions,'x',1))???
为什么要 select ??
好像是可以不要的,但是这样的话,应该可以实现的。 您好,我们是一支有激情有活力的创业团队,目的是教大学生编写代码成为一个合格的程序员。我们现有一个稳定的网站作为支撑,现在要开创新的板块,未来会寻求独立。我们现在有一些导师愿意加盟,但还是远远不够的,希望继续有像您一样的技术牛人的加盟,您只需利用您的碎片化时间就可以了,不知您是否有兴趣继续了解一下呢?
其它类似信息

推荐信息