PostgreSQL内部联接获取3个产品的ID

时间:2016-11-21 04:10:22

标签: postgresql inner-join odoo-9

我有这5个sale_order直接连接到sale_order_line的表,其中包含与product_product连接的product_template连接到mrp_bom的订单产品其中一个名为bom_line的表可以连接到产品模板,另一个表连接到836g。我正在尝试输出包含单词Select so.name, pt.name, sol.name From sale_order so Inner Join sale_order_line sol On so.id = sol.order_id Inner Join product_template pt On sol.product_id = pt.id Inner Join mrp_bom bom On pt.id = bom.product_tmpl_id Inner Join mrp_bom_line boml On bom.id = boml.bom_id Where boml.product_id = (Select id From product_template Where name Like '%836g%' Order By so.name

的产品

这是我到目前为止所做的:

836g

此代码输出错误,因为我有=的3个项目。我尝试将条件中的IN更改为id,以便它会抓取它将返回的所有pub trait DiGraph<'a> { type N; fn nodes<T>(&'a self) -> T where T: Iterator<Item=&'a Self::N>; fn pre<T>(&'a self, node: Self::N) -> T where T: Iterator<Item=&'a Self::N>; fn succ<T>(&'a self, node: Self::N) -> T where T: Iterator<Item=&'a Self::N>; } struct SimpleNode { pre: Vec<usize>, succ: Vec<usize>, } pub struct SimpleDiGraph { pub nodes: Vec<SimpleNode> } impl<'a> DiGraph<'a> for SimpleDiGraph { type N = usize; fn nodes<T=std::ops::Range<usize>>(&'a self) -> T { return std::ops::Range { start: 0, end: self.nodes.len() }; } fn pre<T=std::slice::Iter<'a,usize>>(&'a self, node: usize) -> T { return self.nodes[node].pre.iter(); } fn succ<T=std::slice::Iter<'a,usize>>(&'a self, node: usize) -> T { return self.nodes[node].succ.iter(); } } 。但它仍然给我一个错误。这是我迄今为止最好的,我已经尝试了很多次,但我无法弄清楚。

2 个答案:

答案 0 :(得分:0)

我觉得这些内容是你真正想要的东西:

f(c("a","b","d"), df)
#[1] 0.6
f(c("a","d"), df)
#[1] 1

答案 1 :(得分:0)

OMG!我刚才得到了答案。我不认为这会对任何人有所帮助,但我会发布我的答案

SELECT so.name,
   pt.name PT,
   sol.name SOL,
   (Select pp1.name_template From product_product pp1 Where boml.product_id = pp1.id) BOML,
   boml.product_id

FROM sale_order so INNER JOIN sale_order_line sol     ON so.id = sol.order_id INNER JOIN product_template pt     ON sol.product_id = pt.id INNER JOIN mrp_bom bom     ON pt.id = bom.product_tmpl_id INNER JOIN mrp_bom_line boml     ON bom.id = boml.bom_id WHERE(选择pp1.name_template来自product_product pp1,其中boml.product_id = pp1.id)LIKE&#39;%836g%&#39; ORDER BY so.name

谢谢大家帮助我的努力!我们来到这里的社区很棒! :d