以下提示查询过于复杂,请问有没有什么解决办法?
select * from sale where (shopname='a1' or shopname='a2' or shopname='a3' or ......shopname='a400')
                                    共有400个以上条件
                                    望大侠们帮忙!
                      

解决方案 »

  1.   

    如果shopname來自sale表中所有shopname的值,可以這樣select * from sale where shopname in(select distinct shopname from sale)
      

  2.   

    不是所有值,是shopname部份值....shopname 可以假设为a1--a1000
      

  3.   

    那有唯一鍵可以搜索到這些shopname嗎?比如
    select * from sale where shopname in
    (select distinct shopname from sale where id between 1 and 400)
      

  4.   

    不知道楼主这四百个条件是怎么写出来的?要花好大功夫吧
    我曾经也碰到类似查询,偶尔一用,先在EXCEL中整理编辑好条件再复制到分析器中执行...
      

  5.   

    四百个条件做个循坏就能写出来了.
    我是把所有店铺先读取到listview1中,店铺名称不会重复,有500个吧.
    如果用户要查看所属店铺资料,就在复选柜中把该店铺选择,所以就可以出现同时先择400个店铺了.结果才发现选太多查不了..........
      

  6.   

    你按echiynn(寶琲)就可以了,要用到的条件在in后面用select的where筛选出来不就可以了吗?
      

  7.   

    从LISTBOX里加进去
    if(selectIndex == -1)return;
    stringBuild str = new stringBuild();
    str.AppendFomat("select * from sale where shopname={0}",selectItems[0].Tostring());
    for(int i=1;i<selectItems.count;i++)
    {
      str.AppendFomat(" or shopname={0}",selectItems[i].Tostring()); 
    }
      

  8.   

    有什么特别的要求非要用一条SQL解决么?
    感觉用存储过程更好一些。
      

  9.   

    select * from sale where (shopname='a1' or shopname='a2' or shopname='a3' or ......shopname='a400')--估计楼主的店铺是没有店铺ID的..--在数据库做个ShopId找:select * from sale where ShopId in(客户所选中的ID)
      

  10.   

    用In子句。
    例如:select 月份,员工编号,员工姓名,部门 from GzItem where 
    月份]=0 and 员工编号 in (1,2,3,...)这样可以解决我刚刚也是遇到你同样的问题