0

我有两个表Sizes_description(衣服尺寸)和库存数量。我想知道有哪些尺寸的库存。如果我尝试以下查询,我还会得到没有库存的尺寸。


| SIZES_DESCRIPTION   |
-----------------------
id  size1 size2 size3 
-----------------------
1      M      L     X  
2     40     42    43  
-----------------------

-----------------------------
| STOCK                     |
-----------------------------
id  sizeId qty1 qty2 qty3
-----------------------------
1     2       0    5    0
2     1      42   43    0
-----------------------------

如果我尝试以下方法,我也会得到没有库存的尺寸

select s.size1,s.size2,s.size3 from SIZES_DESCRIPTION as s, stock as stock WHERE s.id=stock.sizeId AND (stock.qty1>0 OR stock.qty2>0 OR qty3>0)
4

1 回答 1

0
Select sd.size1
From sizes_description sd
INNER JOIN Stock s On
sd.id = s.sizeId
Where s.qty1 > 0

UNION ALL

Select sd.size2
From sizes_description sd
INNER JOIN Stock s On
sd.id = s.sizeId
Where s.qty2 > 0

UNION ALL

Select sd.size3
From sizes_description sd
INNER JOIN Stock s On
sd.id = s.sizeId
Where s.qty3 > 0
于 2013-04-23T22:16:58.710 回答