我有三张表depot,仓库表,主键depotId
product,产品表,主键productId,有个字段isPackage
和productStock,库存表,主键productStockId,还有depotId和productId,指向其他两个表
现在要查的是这样的:查库存表,条件是仓库Id=1或者2并且产品的isPackage = 0或者为NULL求SQL语句
product,产品表,主键productId,有个字段isPackage
和productStock,库存表,主键productStockId,还有depotId和productId,指向其他两个表
现在要查的是这样的:查库存表,条件是仓库Id=1或者2并且产品的isPackage = 0或者为NULL求SQL语句
WHERE (depotId = 1 OR depotId = 2) AND (isPackage = 0 OR isPackage IS NULL)
--这样?
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
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
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
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)
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网才少了一个
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
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]