[英]How to use IS NOT NULL in Knex JS
我正在尝试使用knex创建以下查询:
SELECT * FROM users group by users.location having users.photo is not null
如下:
knex("users").groupBy("users.location").having("users.photo", "IS NOT", "Null")
我收到以下错误:
The operator IS NOT is not permitted
我已经阅读了他们的文档,找不到任何有用的东西。
你有没有尝试过:
knex("users").whereNotNull("photo").groupBy("location")
根据文档 , .havingRaw是你需要的:
knex("users").groupBy("users.location").havingRaw("users.photo IS NOT ?", [null]);
另一方面,除非在此特定情况下使用构建器有任何剩余优势,否则请立即执行knex.raw。
文档有答案。 有whereNull
, whereNotNull
, havingNull
, havingNotNull
等等。
来自DOCS :
havingNull - .havingNull(列)
向查询添加havingNull子句。
knex.select('*').from('users').havingNull('email')
输出:
select * from `users` having `email` is null
havingNotNull - .havingNotNull(列)
向查询添加havingNotNull子句。
knex.select('*').from('users').havingNotNull('email')
输出:
select * from `users` having `email` is not null
尝试使用knex查询实验室: http ://michaelavila.com/knex-querylab/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.