分享一个最近遇到的sql冷知识(容易踩坑)
SELECT COALESCE(SUM(a.bamount),0) as sumprice,COUNT(a.itemid) as countorder FROM dtmoban_mall_price a LEFT JOIN dtmoban_member b ON a.userid=b.userid WHERE `status`>=0 and a.types>0 AND (a.checkstatus=0 or a.checkstatus=3) and a.status<>6 and b.support in ('tc134a','tc134b','jw133a','jw13','jw132','jw132a','jw132b','jw132c','jw133b','jw134a','jw134b','jw133d','jw133c','jw134c','jw134d','jw132e','jw132f','jw134e','jw133e','jw131','jw135a','wq531','wq532','wq533','wq534','wq535','wq536','wq538','wq531a','wq532a','wq532b','wq533a','wq533b','wq534a','wq534b','wq534c','wq535a','wq535b','wq535c','wq536a','wq536b','wq536c','wq538a','wq536d','wq533d','wq535d','wq531b','wq536e','wq538b','wq535e','wq538c','wqdt12','wqdt121a','wqdt121b','wqdt121c','wq533q','wq534f','wq532c','wq535f','wq535g','wq531c') UNION ALL SELECT COALESCE(SUM(a.bamount),0) as sumprice,COUNT(a.itemid) as countorder FROM dtmoban_mall_price a LEFT JOIN dtmoban_member b ON a.userid=b.userid WHERE `status`>=0 and a.types>0 AND (a.checkstatus=0 or a.checkstatus=3) and a.status<>6 and b.support in ('tc134a','tc134b','jw133a','jw13','jw132','jw132a','jw132b','jw132c','jw133b','jw134a','jw134b','jw133d','jw133c','jw134c','jw134d','jw132e','jw132f','jw134e','jw133e','jw131','jw135a','wq531','wq532','wq533','wq534','wq535','wq536','wq538','wq531a','wq532a','wq532b','wq533a','wq533b','wq534a','wq534b','wq534c','wq535a','wq535b','wq535c','wq536a','wq536b','wq536c','wq538a','wq536d','wq533d','wq535d','wq531b','wq536e','wq538b','wq535e','wq538c','wqdt12','wqdt121a','wqdt121b','wqdt121c','wq533q','wq534f','wq532c','wq535f','wq535g','wq531c') and a.`status`=4
看上面这段sql,a.status<>6,一开始我看这段sql的时候我是懵逼的,为什么status的状态能大于小于6,这种sql能执行成功?后来我百度了一下,才发现原来sql里面不等于可以用<>来表示,这点是我们很多人会忘记的,或许在刚学习的时候会知道,但是平时大多数人真不用<>表示不等于而是用!=,所以这里也提醒了我一下,要注意细节。同时写代码的时候还是要使用一些大多数人能看懂的语法,修饰符,判断语句等。尤其是在团队合作中,大家还是要尽量保持一致