开发者

MySQL IF replacement for two strings

开发者 https://www.devze.com 2023-03-04 11:16 出处:网络
Grandfathered Database, worst n开发者_运维技巧on normal form data I\'ve ever witnessed.So queries become a pain the arse.

Grandfathered Database, worst n开发者_运维技巧on normal form data I've ever witnessed. So queries become a pain the arse.

I'm trying to match to see if the field is NOT either of these two strings..I've googled my arse off and the REGEXP function isn't all that great.

IF (SUBSTRING_INDEX(op.field_name, '-', 1) != ('CAT','DOG'),
    ps.products_productline ,SUBSTRING_INDEX(op.fieldname, '-',
    1)) AS product_type

The substring index are either Cat, Dog or a Unique string.


Case
When SUBSTRING_INDEX(op.field_name, '-', 1) Not In('CAT','DOG') Then ps.products_productline
Else SUBSTRING_INDEX(op.fieldname, '-', 1)
End AS product_type

Another solution

Case
When op.field_name Like 'CAT-%' Then 'CAT'
When op.field_name Like 'DOG-%' Then 'DOG'
Else ps.products_productline
End AS product_type
0

精彩评论

暂无评论...
验证码 换一张
取 消