如何获取具有特定产品清单的订单清单 这是我的桌子
Order_Id Products_Id
O1 P123
O1 P124
O1 P125
O1 P126
O1 P127
O2 P127
O2 P123
O2 P125
O2 P128
O3 P123
O3 P124
O3 P127
查询以获取产品ID为P127,P123的所有订单的列表(不仅2个项目,动态项目列表) 请帮助我。
关于, 萨蒂亚
答案 0 :(得分:0)
您可以使用 sum() {
this.total = this.people.reduce((a, b)=>a + b);
}
ngOnInit() {
this.sum();
this.max = this.people.reduce((a, b)=>Math.max(a, b));
this.min = this.people.reduce((a, b)=>Math.min(a, b));
this.average = (this.total / this.arrayLength);
}
<span *ngFor="let p of people" style="font-size:18px">{{p}} </span><br><br>
<button >Quantity</button> = {{arrayLength}}<Br><br>
<button >Average</button> = {{average}}<Br><br>
<button >Sum</button> <span > = {{total}}</span><Br><br>
<button >Max</button> <span > = {{max}}</span><Br><br>
<button >Min</button> <span > = {{min}}</span><Br><br>
和group by
:
having
“ 2”是您要寻找的产品数量。
如果不允许重复,则使用select order_id
from orders o
where product_id in ('P127', 'P123')
group by order_id
having count(distinct product_id) = 2;
代替count(*)
。
答案 1 :(得分:0)
您可以如下查询:
SELECT order_id
FROM orders
GROUP BY ORDER_ID
HAVING products_id IN (&products_id);