- 列表项
我试图连接两个表滤除具有唯一值的ITEM_ID,并显示任何 ITEM_ID那包含相同的值。我使用的SQL语句似乎只有一半的工作,除了它返回所有我认为我有这个数字,但我猜不是。组通过柱具有COUNT在单个列(列)> 1
此声明拉动所有内容。
--join two tables filtering out and item_id that has a unique value and displaying any
--item_id that contains the same value
SELECT inv_bin.bin, inv_bin.quantity, inv_bin.inv_bin_uid, inv_bin.inv_mast_uid,
inv_mast.inv_mast_uid,inv_mast.item_desc, inv_mast.item_id
FROM inv_bin left join inv_mast on inv_bin.inv_mast_uid = inv_mast.inv_mast_uid
WHERE inv_mast.item_id in (SELECT item_id from inv_mast
GROUP BY item_id HAVING COUNT (item_id) >= 1)
AND inv_bin.bin not like 'rec'
AND inv_bin.bin not like 'DEFBIN'
AND inv_bin.bin not like 'DEFAULTBIN'
ORDER BY inv_mast.item_id;
但是,如果我从Group By item_id Having COUNT (item_id) >= 1)
删除'='
那么该查询返回任何内容。我知道我在ITEM_ID列数据是一样的:
bin item_id
07C-C15 002-09-121
Z07-OS 002-09-121
反正能有人告诉我,我要去的地方错了这一点,在我看来,这期运用> 1将显示每一件事的ITEM_ID与相同的价值。
感谢, 布雷特
bin quantity inv_bin_uid inv_mast_uid inv_mast_uid item_id
07C-C15 0 135 70 70 002-09-121
Z07-OS 10 130277 70 70 002-09-121
04C-B21 0 354 289 289 032-36-26
04C-B04 0 356 291 291 032-38-26
02A-B01 2 101 48 48 5-40050720L
Z29-SKID00 0 117 48 48 5-40050720L
这里是产生期望reults成品声明。
/*join two tables filtering out and item_id that has a unique value and displaying any
item_id that contains the same value */
SELECT inv_bin.bin, inv_bin.quantity, inv_bin.inv_bin_uid, inv_bin.inv_mast_uid,
inv_mast.item_desc, inv_mast.item_id
from inv_bin left join inv_mast on inv_bin.inv_mast_uid = inv_mast.inv_mast_uid
where inv_bin.inv_mast_uid in (
SELECT inv_mast_uid FROM inv_bin
WHERE inv_bin.bin NOT IN ('REC','DEFBIN','DEFAULTBIN')
GROUP BY inv_mast_uid HAVING COUNT(inv_mast_uid)>1)
and inv_bin.bin not like 'rec'
and inv_bin.bin not like 'defbin'
and inv_bin.bin not like 'Defaulbin'
/*look up filtering out ids based on not like statements*/
ORDER BY inv_bin.inv_mast_uid;
再次感谢您的所有帮助。
我认为一些示例数据会有所帮助。 – 2013-02-15 19:00:39
你确定你要违反正确的数据库吗?这应该工作... – xandercoded 2013-02-15 19:06:07
注释掉你的'AND inv_bin.bin不喜欢'rec' AND inv_bin.bin不喜欢'DEFBIN' AND inv_bin.bin不喜欢'DEFAULTBIN''和看? – Kaf 2013-02-15 19:06:27