MySQL IF replacement for two strings
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
精彩评论