今天写了一个错误SQL语句,但是MYSQL在某些条件时才报错,而且错误莫名其妙:
Column 'inviteUserId' cannot be null
最后才发现内查询少了group by 语句
select t1.price, t2.*, t1.price*t2.effectUserCount sumMoney, t1.price*t2.undealUserCount undealMoney from inviteSys_seller t1,
(select inviteUserId, sum(1) sumUser, sum(status=1) effectUserCount, sum(status=1 and deal=0) undealUserCount from inviteSys_user where inviteUserId=10004136) t2 where t1.userId=t2.inviteUserId
正确的语句应该是
select t1.price, t2.*, t1.price*t2.effectUserCount sumMoney, t1.price*t2.undealUserCount undealMoney from inviteSys_seller t1,
(select inviteUserId, sum(1) sumUser, sum(status=1) effectUserCount, sum(status=1 and deal=0) undealUserCount from inviteSys_user where inviteUserId=10004136group by inviteUserId) t2
where t1.userId=t2.inviteUserId
这算是MYSQL的BUG吗