魔兽世界声望怎么获得:on和where的争夺战
来源:百度文库 编辑:九乡新闻网 时间:2024/05/02 02:31:01
今天遇到一个数据库查询问题:两个表之间的连接的on过滤和where过滤的问题。一般来说是在on后面的条件是两个表之间连接条件,也就是两个表之间的对应字段等于起来;where后面的条件是用传进来的一些参数对上面连接过后的条件再过滤。如下:select 1 from t_herotask ht inner join t_task t on ht.taskid=t.code
inner join t_taskobjective tbj on t.id=tbj.taskID and tbj.ItemType <> '2'
left outer join t_card card on ht.heroId=card.heroId and card.typeid = tbj.ItemCode
where ht.heroId=@heroID and t.code=@taskID and card.CONTAINERTYPE=1
group by card.typeid, t.id having sum(CURRENTSTACKS) is NULL OR
(select sum(tbj.num) from t_taskobjective tbj where tbj.taskid=t.id and tbj.
itemcode=card.typeid and tbj.itemtype<>'2') > sum(CURRENTSTACKS)) 但是这样不行必须要,必须要这样才行:select 1 from t_herotask ht inner join t_task t on ht.taskid=t.code
inner join t_taskobjective tbj on t.id=tbj.taskID and tbj.ItemType <> '2'
left outer join t_card card on ht.heroId=card.heroId and card.typeid = tbj.ItemCode
and card.CONTAINERTYPE=1
where ht.heroId=@heroID and t.code=@taskID
group by card.typeid, t.id having sum(CURRENTSTACKS) is NULL OR
(select sum(tbj.num) from t_taskobjective tbj where tbj.taskid=t.id and tbj.
itemcode=card.typeid and tbj.itemtype<>'2') > sum(CURRENTSTACKS))上面的移上去的条件不是从外面传进来的值,而只是简单过滤一下这个字段,但是不知道什么原因,像下面这样把本来应该放在where后面的条件过滤放到on后面就不行。难道SQL语句的执行就是这样的?很是神奇。。。 最后得出了一个结论:如果过滤的条件里没有用到外部传值就放在on后面,否则就放在where后,当然只是在表间连接的时候才会用on这个关键词哈!!
inner join t_taskobjective tbj on t.id=tbj.taskID and tbj.ItemType <> '2'
left outer join t_card card on ht.heroId=card.heroId and card.typeid = tbj.ItemCode
where ht.heroId=@heroID and t.code=@taskID and card.CONTAINERTYPE=1
group by card.typeid, t.id having sum(CURRENTSTACKS) is NULL OR
(select sum(tbj.num) from t_taskobjective tbj where tbj.taskid=t.id and tbj.
itemcode=card.typeid and tbj.itemtype<>'2') > sum(CURRENTSTACKS)) 但是这样不行必须要,必须要这样才行:select 1 from t_herotask ht inner join t_task t on ht.taskid=t.code
inner join t_taskobjective tbj on t.id=tbj.taskID and tbj.ItemType <> '2'
left outer join t_card card on ht.heroId=card.heroId and card.typeid = tbj.ItemCode
and card.CONTAINERTYPE=1
where ht.heroId=@heroID and t.code=@taskID
group by card.typeid, t.id having sum(CURRENTSTACKS) is NULL OR
(select sum(tbj.num) from t_taskobjective tbj where tbj.taskid=t.id and tbj.
itemcode=card.typeid and tbj.itemtype<>'2') > sum(CURRENTSTACKS))上面的移上去的条件不是从外面传进来的值,而只是简单过滤一下这个字段,但是不知道什么原因,像下面这样把本来应该放在where后面的条件过滤放到on后面就不行。难道SQL语句的执行就是这样的?很是神奇。。。 最后得出了一个结论:如果过滤的条件里没有用到外部传值就放在on后面,否则就放在where后,当然只是在表间连接的时候才会用on这个关键词哈!!
on和where的争夺战
Where Hunger Goes: On the Green Revolution
I never knew where to move on
民工争夺战的启示
鲜为人知的梅兰芳争夺战
柬、泰争夺战的柏威夏寺
张亚勤:PC之外的争夺战
张亚勤:PC之外的争夺战
144种星座配对 (其实 你看 狮子和天枰在一起 真的很配)where'd you go i miss you so
文件管理的得力助手——Where Is It
古代中日之间的“面子争夺战”
津秦高铁叫停背后的站点争夺战
老赵的“地下车库”争夺战
玩转Canon的AF-ON、自动曝光锁和快门按钮
玩转Canon的AF-ON、自动曝光锁和快门按钮
★★★as?a?whole?和?on?the?whole的区别
俞力工:非洲大湖区灾难背后的资源争夺战-13
盘点中国古典名著里名胜古迹的现代争夺战
春天里的民工荒:中国东西部劳动力争夺战
春天里的民工荒中国东西部劳动力争夺战
第一把交椅争夺战:赫鲁晓夫的“逼宫”与“被逼宫”
发生在中央苏区的稀有矿藏争夺战
第一把交椅争夺战:赫鲁晓夫的“逼宫”与“被逼宫”
高华:共产党与国民党的革命理论争夺战