使用一个查询计算产品详情中的每个产品订单

时间:2015-07-03 12:10:21

标签: php mysql sql database codeigniter

mysql db中有2个表:

products: id, ...
products_order: id, pid,
                     ^
                 products.id

在产品详情页面中如何显示每个产品'订单(例如,此产品由4个人订购),无需查询每个产品。 例如

select count(*) from products_order where pid = 1

获得如下结果:

pid    count
 1       5
 2       12
 3       1
 4       32
...     ...

因为那里有一个20的分页,我已经尝试了

SELECT COUNT(*) FROM products WHERE pid IN (1,2,3,4, ... 20)

但它并没有给我我想要的东西。

1 个答案:

答案 0 :(得分:0)

使用此sql

Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                            try {
                                MainActivity.this.startActivity(goToMarket);
                            } catch (ActivityNotFoundException e) {
                                MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName())));
                            }
相关问题