我正在尝试访问三个表以获得如下内容:
+------+------+------+
| ITEM | PCS | CSS |
+------+------+------+
| 1099 | 2 | 11 |
| 1098 | 2 | 2 |
| 1097 | 2 | 1 |
| 1096 | NULL | NULL |
| 1095 | NULL | NULL |
| 1094 | NULL | NULL |
| 1093 | NULL | NULL |
| 1092 | NULL | NULL |
+------+------+------+
但是,我得到的只是:
+------+------+------+
| ITEM | PCS | CSS |
+------+------+------+
| 1099 | 2 | 11 |
| 1098 | 2 | 2 |
| 1097 | 2 | 1 |
+------+------+------+
//我对我的查询有点困惑,所以这里是我想要做的事情的细分:
SELECT CODE
FROM SET2
WHERE MO = MONTH(SYSDATE())
AND YR = YEAR(SYSDATE())
//and then:
SELECT ITEM, PCS, CSS
FROM SET3
WHERE S3.CODE=S2.CODE
//then:
SELECT ITEM
FROM SET1
WHERE S1.ITEM=S3.ITEM
我的桌子
SET1
+------+
| ITEM |
+------+
| 1099 |
| 1098 |
| 1097 |
| 1096 |
| 1095 |
| 1094 |
| 1093 |
| 1092 |
+------+
SET2
+------+-----+------+
| YR | MO | CODE |
+------+-----+------+
| 2013 | 1 | 1 |
| 2013 | 2 | 2 |
+------+-----+------+
SET3
+------+-----+------+------+
| PCS | CSS | CODE | ITEM |
+------+-----+------+------+
| 2 | 11 | 1 | 1099 |
| 2 | 2 | 1 | 1098 |
| 2 | 1 | 1 | 1097 |
+------+-----+------+------+