首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

初学者求指点sql语句的有关问题

2013-02-19 
菜鸟求指点sql语句的问题1.select * from file_table where (useridzhangsan or useridALL USER) an

菜鸟求指点sql语句的问题
1.select * from file_table where (userid='zhangsan' or userid='ALL USER') and filename like '1k%' 
2.select * from file_table where userid='zhangsan' or userid='ALL USER' and filename like '1k%' 

在前面加括号的情况下,模糊查询能成功,在后面不加括号的情况下模糊查询就不能成功。
为什么?or的优先级大于所有的and吗
sql
[解决办法]
(a=1 or b=2) and c=3
a=1 or b=2 and c=3  ======> a=1 or (b=2 and c=3)

所以兩句是不一樣的。

[解决办法]
不加括号相当于
select * from file_table where userid='zhangsan' or 
(userid='ALL USER' and filename like '1k%')
显然与你的原意不符

热点排行