如何解决如何将 SQL 查询转换为 firebase 实时数据库查询?
在这里,我试图获取客户一起购买的产品。这里是表格
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 查询中得到了准确的输出,但在 ionic 中的 angularfirelist firebase 实时数据库中不知道。谁能帮我解决这个查询。
提前致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。