我第一次在巨大的数据库上运行sql语句,并且我有这样的代码。
Select x, sum(y), sum(z) from db
where n = 'xxx' or 'yyy' and m = int
group by x
现在,如果我这样做
Select x, sum(y), sum(z) from db
where n = 'xxx' and m = int
group by x
Select x, sum(y), sum(z) from db
where n = 'yyy' and m = int
group by x
并手动将2个表中的分组值加在一起,我在查询中得到不同的结果,而分开的查询更准确。
例如第1行的结果在第一个查询中将为2000万,第二行代码中将第1行相加的结果将为1800万?不确定是什么问题...?
[与AND一起使用时,请在OR周围使用括号
Select x, sum(y), sum(z) from db
where (n = 'xxx' or 'yyy') and m = int
group by x