我有三张表depot,仓库表,主键depotId
product,产品表,主键productId,有个字段isPackage
和productStock,库存表,主键productStockId,还有depotId和productId,指向其他两个表
现在要查的是这样的:查库存表,条件是仓库Id=1或者2并且产品的isPackage = 0或者为NULL求SQL语句

解决方案 »

  1.   

    SELECT * FROM productStock
    WHERE (depotId = 1 OR depotId = 2) AND (isPackage = 0 OR isPackage IS NULL)
      

  2.   


    --这样?
    select c.* from depot a,product b ,productstock c
    where a.depotid=c.depotid and b.productid=c.productid and depotid in(1,2)
    and isnull(b.ispackage,0)=0
      

  3.   


    select a.*,b.*,c.*
      from depot a inner join  productStock b on a. depotId =b.depotId  and (a.depot=1 or depot=2)
            inner  join product c on b.productId=c.productId
      

  4.   


    select 
     c.* 
    from 
     depot a,product b ,productstock c
    where 
     a.depotid=c.depotid 
    and 
     b.productid=c.productid 
    and 
     depotid in(1,2)
    and 
     isnull(b.ispackage,0)=0
      

  5.   


    select c.* from depot a,product b ,productstock c
    where a.depotid=c.depotid and b.productid=c.productid and depotid in(1,2)
    and (b.ispackage is null or  b.ispackage=0)
      

  6.   

    select a.*,b.*,c.*
      from depot a inner join  productStock b on a. depotId =b.depotId 
            and (a.depot=1 or depot=2) and isnull(ispackage,0)=0
            inner  join product c on b.productId=c.productId网才少了一个
      

  7.   

    select top 30 _ProductStock.[productStockId] as _column1 from [ProductStock] as _ProductStock left join [Product] as _Product on _Product.[productId] = _ProductStock.[productId] left join [Depot] as _Depot on _Depot.[depotId] = _ProductStock.[depotId] where( '1' = '2' or _ProductStock.[depotId] = 1 or _ProductStock.[depotId] = 2 )
      

  8.   


    select 
     c.* 
    from 
     depot a,product b ,productstock c
    where 
     a.depotid=c.depotid 
    and 
     b.productid=c.productid 
    and 
     depotid in(1,2)
    and 
     isnull(b.ispackage,0)=0
      

  9.   

    select from productStock ps inner join product pd on ps.productId=pd.productId where (ps.depotId=1 or ps.depotId=2) and (pd.isPackage=0 or pd.isPackage is Null)
      

  10.   

    select top 30 _ProductStock.[productStockId] as _column1 from [ProductStock] as _ProductStock left join _Product.[Product] as _Product on _Product.[productId] = _ProductStock.[productId] left join _Depot.[Depot] as _Depot on _Depot.[depotId] = _ProductStock.[depotId] where( (_ProductStock.[depotId] = 1 or _ProductStock.[depotId] = 2) AND  (_Product.isPackage ='0' or _Product.isPackage = null) )
      

  11.   

    我有三张表depot,仓库表,主键depotId 
    product,产品表,主键productId,有个字段isPackage 
    和productStock,库存表,主键productStockId,还有depotId和productId,指向其他两个表 
    现在要查的是这样的:查库存表,条件是仓库Id=1或者2并且产品的isPackage = 0或者为NULL 求SQL语句 
    楼主可以试下:[color=#FF0000]
    select * from 库存表 where (productStockId=1 or productStockId=2) and productId in (select productId from 产品表 where isPackage=0 or isPackage=null)[/color]
      

  12.   

    select * from 库存表 where (productStockId=1 or productStockId=2) and productId in (select productId from 产品表 where isPackage=0 or isPackage=null)
      

  13.   

    select * from 库存表 where (productStockId=1 or productStockId=2) and productId in (select productId from 产品表 where isPackage=0 or isPackage is null)