我只希望列可见为1的结果。如果列值为0,则不应返回该行。
这是我期望的结果,但是我看到除 visible 检查之外的所有与where子句匹配的行。
我怀疑我的优先顺序是不正确的,但是从我的阅读和理解中,我的查询看起来像是从“ FROM”,“ WHERE”,“ GROUP BY”,“ SELECT”,“ ORDER BY”。
从:应该获得三个表,并根据我的条件将它们连接在一起。
位置:然后应过滤列 visible = 1的所有行,排除所有为0的行。并匹配两个子查询中的任何一个。
组依据:然后将每个部件号分组在一起,将重复的部件号绑定为一个。
这是输出:
<table border=1px>
<thead>
<tr>
<th>part_number</th>
<th>part_description</th>
<th>stock</th>
<th>visible</th>
</tr>
</thead>
<tbody>
<tr>
<td>M2043PR</td>
<td>part_desc_here</td>
<td>50</td>
<td>0</td>
</tr>
<tr>
<td>2E0615601A/XX</td>
<td>part_desc_here</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>400647720</td>
<td>part_desc_here</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table
以下是查询:
SELECT part_number, part_description, stock, visible
FROM tbl__crossref AS r INNER JOIN tbl__pno AS p
ON r.id_pno = p.id
INNER JOIN tbl__inventory AS inv
ON p.pno = inv.part_number
WHERE inv.visible= 1
AND r.id_pno IN
(
SELECT pref.id_pno
FROM tbl__crossref AS pref INNER JOIN tbl__pno AS p
ON pref.id_pno = p.id
INNER JOIN tbl__oe AS o
ON pref.id_oe = o.id
WHERE p.pno LIKE '%M2043%'
OR o.oe LIKE '%M2043%'
)
OR r.id_oe IN
(
SELECT pref.id_oe
FROM tbl__crossref AS pref INNER JOIN tbl__pno AS p
ON pref.id_pno = p.id
INNER JOIN tbl__oe AS o
ON pref.id_oe = o.id
WHERE p.pno LIKE '%M2043%'
OR o.oe LIKE '%M2043%'
)
GROUP BY inv.part_number
ORDER BY inv.stock DESC
LIMIT 100;
为什么我的结果显示的可见行= 0