我有这个问题:
String queryStr = 'SELECT COUNT(*) FROM tester x WHERE x.state !=:state'
setParameter("state", "state1");
我想要计算所有“state1”和“state2” 有没有办法做到而不是:
String queryStr = 'SELECT COUNT(*) FROM tester x WHERE (x.state !=:state1 AND x.state !=:state2)';
setParameter("state1", "state1");
setParameter("state2", "state2");
由于
答案 0 :(得分:0)
不在
中使用WHERE (x.state NOt IN (:state1,:state2))
那么你的整个查询将是
'SELECT COUNT(*) FROM tester x WHERE (x.state NOt IN (:state1,:state2))';
注意:上面的解决方案是根据您的查询,但根据您的文字[我想要计算所有“state1”和“state2”]
然后您的查询可以
'SELECT COUNT(*) FROM tester x WHERE x.state = :state1 AND x.state = :state2';