首页 > 解决方案 > 如何用一个查询在两列中搜索

问题描述

如果一对一不为空或返回值不为零,则有必要查看两列。如果 mURL === "string" 和 aURL === NULL 返回值

{

    logging: console.log,
    attributes: ['firstName','lastName','email','mURL','aURL'],
    where: {
      mURL: {
        $not: null
      },
      aURL: {
         $not: null
        }
      },        
      include: [
        { all: true, nested: true }
      ]

}

标签: sequelize.js

解决方案


尝试以下 -

{
logging: console.log,
attributes: ['firstName','lastName','email','mURL','aURL'],
where: {
  $or: {
    mURL: {
      $not: null
    },
    aURL: {
      $not: null
    }
  }
  },        
include: [
    { all: true, nested: true }
  ]

}

可以使用$and$or运算符。

或者你可以使用 -

where: Sequelize.literal(`(mURL IS NOT NULL) OR (aURL IS NOT NULL)`)

推荐阅读