注册 登录
编程论坛 SQL Server论坛

问题菜鸟问题

菜鸟问菜问题 发布于 2010-06-29 15:02, 519 次点击
大家好,我是新来的菜鸟,我学SQL才几天,有好多问题都不知道,以后请多多照顾。
请问各位大虾下面我这个语句有什么问题?
select SHOPID,SDATE,lcate,xse
From storesale_nrate
 where (shopid ='012010'  
 and sdate between '20100601'and '20100610')or (shopid='012010' and sdate between '20100501'and '20100510') and (select shopid,saledate,billcount from cust_info
where shopid ='012010' and saledate between '20100601'and '20100610')
2 回复
#2
happynight2010-06-30 11:37
select SHOPID,SDATE,lcate,xse
From storesale_nrate
where (shopid ='012010'  and sdate between '20100601'and '20100610')
   or (shopid='012010' and sdate between '20100501'and '20100510')
   and EXISTS(select shopid,saledate,billcount from cust_info
        where shopid ='012010' and saledate between '20100601'and '20100610')
一.你提问要把错误提示最好也贴上来,毕竟别人没法在你的数据环境下调试
二.你的错误应该是少了"EXISTS"
三.你逻辑上应该还有个错误 你的"OR"和"AND"操作没有用括号分隔,这样的查询返回的结果肯定不是你想要的
select SHOPID,SDATE,lcate,xse
From storesale_nrate
where ((shopid ='012010'  and sdate between '20100601'and '20100610')
   or (shopid='012010' and sdate between '20100501'and '20100510'))
   and EXISTS(select shopid,saledate,billcount from cust_info
        where shopid ='012010' and saledate between '20100601'and '20100610')
#3
菜鸟问菜问题2010-06-30 16:38
谢谢啊,大哥,以后还请多多指教
1