Mysql的案例 - 如果 - 那么 - 返回错误的数据类型(BLOB)
-
23-09-2019 - |
题
林创建定制的产品属性在网络商店 - 每个属性可以具有不同的类型,每种数据类型使用对应的MySQL数据类型存储在一个单独的列数据的
我有这样的查询:
SELECT
products.id AS id,
products.sku AS sku,
products.name AS name,
products.url_key AS url_key,
attributes.name AS attribute,
CASE
WHEN `attribute_types`.`type` = 'text'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'float'
THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'price'
THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'integer'
THEN product_attribute_values.value_integer
WHEN `attribute_types`.`type` = 'multiple'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'dropdown'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'date'
THEN product_attribute_values.value_date
WHEN `attribute_types`.`type` = 'textarea'
THEN product_attribute_values.value_textarea
END as value
from (...)
现在,问题是,当attribute_types
.type
等于?一些型?我想,因为它是存储在product_attribute_values
表它返回一个值。
目前,我每次得到的BLOB。
我应该使用类型强制转换或有一些背后的场景魔术,我不知道,也许有一些更好的选择?
编辑:
一切都显得OKAY(IM检查价格是浮动),直到我对TEXT(文本区域)添加条件。
没有正确的解决方案
其他提示
看来你使用的是一些查询浏览器。试图通过“修补剂”执行此命令。
此外,为了得到正确的输出,即使在查询浏览器,包括CAST功能在你这样的CASE语句。
CAST(
CASE
WHEN `attribute_types`.`type` = 'text'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'float'
THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'price'
THEN product_attribute_values.value_float
WHEN `attribute_types`.`type` = 'integer'
THEN product_attribute_values.value_integer
WHEN `attribute_types`.`type` = 'multiple'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'dropdown'
THEN product_attribute_values.value_text
WHEN `attribute_types`.`type` = 'date'
THEN product_attribute_values.value_date
WHEN `attribute_types`.`type` = 'textarea'
THEN product_attribute_values.value_textarea
END
AS CHAR) as value
不隶属于 StackOverflow