下面2句sql差别就是一对括号,我本以为都可达到相同的目的,但是查询出记录不同,谁能给我解释一下呢?1.
select count(distinct taxpayernum) count
from ds_user u
left join ds_stamp e on u.taxpayernum = e.tpayer_id
left join ds_zero_decl d on u.taxpayernum = d.taxper_id
where e.stamp_id is not null
or d.zero_decl_seq is not null
and u.isparent = '1'
and u.usertype = '0'
and u.isinuse in ('5', '1')2.
select count(distinct taxpayernum) count
from ds_user u
left join ds_stamp e on u.taxpayernum = e.tpayer_id
left join ds_zero_decl d on u.taxpayernum = d.taxper_id
where (e.stamp_id is not null
or d.zero_decl_seq is not null)
and u.isparent = '1'
and u.usertype = '0'
and u.isinuse in ('5', '1')
select count(distinct taxpayernum) count
from ds_user u
left join ds_stamp e on u.taxpayernum = e.tpayer_id
left join ds_zero_decl d on u.taxpayernum = d.taxper_id
where e.stamp_id is not null
or d.zero_decl_seq is not null
and u.isparent = '1'
and u.usertype = '0'
and u.isinuse in ('5', '1')2.
select count(distinct taxpayernum) count
from ds_user u
left join ds_stamp e on u.taxpayernum = e.tpayer_id
left join ds_zero_decl d on u.taxpayernum = d.taxper_id
where (e.stamp_id is not null
or d.zero_decl_seq is not null)
and u.isparent = '1'
and u.usertype = '0'
and u.isinuse in ('5', '1')
or d.zero_decl_seq is not null
and u.isparent = '1 '
and u.usertype = '0 '
and u.isinuse in ( '5 ', '1 ') 等于:
where e.stamp_id is not null
or (d.zero_decl_seq is not null
and u.isparent = '1 '
and u.usertype = '0 '
and u.isinuse in ( '5 ', '1 ') )
明白了吧。
先计算and后匹配or,所以LZ的疑惑就解开了