Angular 如何对firebase角度列表进行连接查询?
在这里,我试图获得客户一起购买的产品。这是桌子Angular 如何对firebase角度列表进行连接查询?,angular,firebase,firebase-realtime-database,ionic4,angularfire,Angular,Firebase,Firebase Realtime Database,Ionic4,Angularfire,在这里,我试图获得客户一起购买的产品。这是桌子 order ---- |id| |--| |1 | |2 | |3 | |4 | |5 | order_item ---- |order_id|sku| |------------| | 1 | A | | 1 | B | | 1 | C | | 2 | B | | 2 | A | | 3 | A | | 4 | B | | 4 | A | | 5 | B
order
----
|id|
|--|
|1 |
|2 |
|3 |
|4 |
|5 |
order_item
----
|order_id|sku|
|------------|
| 1 | A |
| 1 | B |
| 1 | C |
| 2 | B |
| 2 | A |
| 3 | A |
| 4 | B |
| 4 | A |
| 5 | B |
| 5 | C |
这些是我试图得到经常一起购买的产品的表格
SQL查询:
select a.sku, count(*) as pcount
from order_item a
join (select distinct order_id from order_item where sku = 'A') b on (a.order_id = b.order_id)
where a.sku != 'A'
group by a.sku
order by pcount desc;
输出:
| sku |pcount|
|----------- |
| B | 3 |
| C | 1 |
这里是firebase数据库查询
this.db.list('/order_item',ref => ref.orderByChild('sku')).valueChanges().subscribe((tableoneresult) => {
this.db.list('/order_item',ref => ref.orderByChild('sku').equalTo('A')).valueChanges().subscribe((res) => {
console.log('related product table second '+res.length);
});
console.log('related product table one '+tableoneresult.length);
});
我想得到与产品A一起购买的其他产品的数量。我在SQL查询中得到了确切的输出,但在爱奥尼亚的angularfirelist firebase实时数据库中不知道。有人能帮我解决这个问题吗
提前谢谢