如何在反对js中使用find_in_set?
How to use find_in_set in objection js?
我有一个包含逗号分隔字符串的列,我需要找到该字符串中包含的确切值。
您可以使用以下语法查找将在 whereIn
中匹配的值
knex.select('name').from('users').whereIn('id', [1, 2, 3])
输出:
select name from users where id in (1, 2, 3)
考虑类别包含逗号分隔值,如 "Food, Clothings, ecommerce"。
Model.select(['id', 'categories']).whereRaw(`FIND_IN_SET('Clothings')`, categories)
我有一个包含逗号分隔字符串的列,我需要找到该字符串中包含的确切值。
您可以使用以下语法查找将在 whereIn
中匹配的值knex.select('name').from('users').whereIn('id', [1, 2, 3])
输出:
select name from users where id in (1, 2, 3)
考虑类别包含逗号分隔值,如 "Food, Clothings, ecommerce"。
Model.select(['id', 'categories']).whereRaw(`FIND_IN_SET('Clothings')`, categories)