SELECT * FROM 表名 WHERE 字段名 IS NOT NULL AND 字段名 <> '';
查询多条件查询,我的业务是这样的:
查询
project is_delete 符合条件并且shared_band_width_id 不为null或者不符合条件的数据。
SELECT * FROM `eip` WHERE project_id='1111' and is_delete='0'
and (shared_band_width_id is null or shared_band_width_id <> '111' )
spring boot jpa操作:
@Query(value = "SELECT * from eip where project_id=?1 and is_delete=?2 and(shared_band_width_id is null or shared_band_width_id <>?3)",nativeQuery = true)
List<Eip> getEipListNotBinding(String projectId, int isDelete, String sbwId);
注意,@Query注解属性中必须加:
nativequery = true
否则,写的Sql会报错,因为要使用原生的SQL
至于什么SQL和原生SQL的区别,我自己还没整明白,搞懂了再更