我在dealer_price(type string)字段中具有以下值:

| dealer_price |

| -------- |

| 1000.00|

| 5000.00|

| Contact for pricing|

| 10000.00|

我有以下查询以执行算术操作:

select (dealer_price + 10) AS cust_price FROM my_table

我想检查查询中每一行的field_type如果field_type是字符串,则仅显示字符串并且是数字,然后执行算术操作。现在在查询之上,将字符串视为0并执行操作。基本上希望像以下查询那样输出:

| cust_price |

| -------- |

| 1010.00|

| 5010.00|

| Contact for pricing|

| 10010.00|
分析解答

您可以使用案例语句检查dealer_price值的数据类型:

SELECT
    CASE
        WHEN dealer_price REGEXP '^[0-9]*[.]{0,1}[0-9]*$' THEN dealer_price + 10
        ELSE dealer_price
    END AS cust_price
FROM my_table;