mysql 中 and和 or 关键字的用法

mysql 中and和or 查询的用法 直接上实列

1.该条sql 表示从 sc_inventory_history 中查询出  storage_id =1 或者 (goods_id=8033 并且 record_date='2019-03-18') 的值

select * from sc_inventory_history where storage_id =1 or goods_id=8033 and record_date='2019-03-18'

2.该条sql 表示查询表示storage_id =1 并且 record_date='2019-03-18'或者goods_id=8033 并且 record_date='2019-03-18'

select * from sc_inventory_history where (storage_id =1 or goods_id=8033) and record_date='2019-03-18' 

 因为 () 的优先级会比 and 和 or 高  所以会先执行 ()里的

你可能感兴趣的:(sql)