sql语句中的and 和or能有多个吗?另外如果语句sql语句中只能有一个and的话那当有多个条件限制时怎么办?
sql="selecttop16*fromtb_goodswhereidnotin(selecttop"+(nowPage*16)+"idfromtb_goodswher...
sql="select top 16 * from tb_goods where id not in (select top "+(nowPage*16)+" id from tb_goods where classes='"+classes2+"' and price<=500 order by id asc)and classes='"+classes2+"',price<=500";
sql="select top 16 * from tb_goods where id not in (select top "+(nowPage*16)+" id from tb_goods where classes='"+classes2+"' and price<=500 order by id asc)and classes='"+classes2+"',price<=500";这条语句对吗? 展开
sql="select top 16 * from tb_goods where id not in (select top "+(nowPage*16)+" id from tb_goods where classes='"+classes2+"' and price<=500 order by id asc)and classes='"+classes2+"',price<=500";这条语句对吗? 展开
2个回答
展开全部
楼主写的是分页算法。
and classes='"+classes2+"',price<=500 这样是不对的,将逗号改成 and
另外,外面的select没有加order by ,可能分页结果不准确。
SQL中可以以多个AND或OR,当条件混乱时,可以使用括号。
如a and (b or c)这样的。
楼主补充的语句可以修改为
sql="select top 16 * from tb_goods where id not in (select top "+(nowPage*16)+" id from tb_goods where classes='"+classes2+"' and price<=500 order by id asc)and classes='"+classes2+"' and price<=500 order by id asc";
and classes='"+classes2+"',price<=500 这样是不对的,将逗号改成 and
另外,外面的select没有加order by ,可能分页结果不准确。
SQL中可以以多个AND或OR,当条件混乱时,可以使用括号。
如a and (b or c)这样的。
楼主补充的语句可以修改为
sql="select top 16 * from tb_goods where id not in (select top "+(nowPage*16)+" id from tb_goods where classes='"+classes2+"' and price<=500 order by id asc)and classes='"+classes2+"' and price<=500 order by id asc";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询