获取多对多表中未映射记录的计数
我有 3 个表,例如
Product
ProductID | ProductDetails |
---|---|
1 | ... |
2 | ... |
3 | ... |
Vendor
VendorID | VendorDetails |
---|---|
1 | ... |
2 | ... |
3 | ... |
ProductVendors
ProductID | VendorID |
---|---|
1 | 1 |
2 | 1 |
1 | 2 |
2 | 2 |
3 | 2 |
我如何查找未映射到特定供应商的产品数量。
我尝试过:
SELECT
COUNT(pr.id) AS product_count
FROM
products pr
LEFT JOIN vendor_product_map vp ON
pr.id = vp.product
LEFT JOIN vendors vv ON
vp.vendor = vv.id
WHERE
vv.id = 3 AND vp.vendor IS NULL
但这似乎不对。任何帮助表示赞赏
I have 3 tables as such
Product
ProductID | ProductDetails |
---|---|
1 | ... |
2 | ... |
3 | ... |
Vendor
VendorID | VendorDetails |
---|---|
1 | ... |
2 | ... |
3 | ... |
ProductVendors
ProductID | VendorID |
---|---|
1 | 1 |
2 | 1 |
1 | 2 |
2 | 2 |
3 | 2 |
How would I go about finding the number of products that are not mapped to a specific vendor.
I tried:
SELECT
COUNT(pr.id) AS product_count
FROM
products pr
LEFT JOIN vendor_product_map vp ON
pr.id = vp.product
LEFT JOIN vendors vv ON
vp.vendor = vv.id
WHERE
vv.id = 3 AND vp.vendor IS NULL
but that doesn't seem right. Any help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个简单的
not contains
查询就足够了:A simple
not exists
query should be sufficient: