Propel:需要以下 SQL 查询的条件
经过半天的头痛试图找出双重 INNER JOIN 后,我终于猜对了:
SELECT product.id as product_id, count(purchase_vaucher.object_id) as purchased
FROM purchase_vaucher
INNER JOIN purchase on purchase.id = purchase_vaucher.object_id
INNER JOIN product on purchase.product_id = product.id
WHERE purchase.is_paid=1
GROUP BY product.id
ORDER BY purchased_amount desc;
这是关于什么的:基本上,三个表:product
、purchase
、< code>purchase_vaucher (是的,我知道它是“优惠券”,但我没有发明该模式)。基本上,purchase
包含所进行的购买以及指向产品
的反向链接。 purchase_vaucher
包含有关优惠券的信息和购买
的反向链接。我在此查询中需要的内容:对于拥有 is_paid=1
的所有 purchase
,计算具有相同产品 ID 的所有购买的所有优惠券,并按产品 ID 将它们分组。
我需要的是:将上述查询翻译为 Propel Criteria API 调用。
我马上就开始做这件事,但如果我能节省一些时间,我会很高兴。
谢谢。
After half a day of headaches trying to figure out a double INNER JOIN, I finally got it right:
SELECT product.id as product_id, count(purchase_vaucher.object_id) as purchased
FROM purchase_vaucher
INNER JOIN purchase on purchase.id = purchase_vaucher.object_id
INNER JOIN product on purchase.product_id = product.id
WHERE purchase.is_paid=1
GROUP BY product.id
ORDER BY purchased_amount desc;
What is this about: basically, three tables: product
, purchase
, purchase_vaucher
(yeah I know it's "voucher", but I didn't invent the schema). Basically, purchase
contains purchases made and a back-link to a product
. purchase_vaucher
contains info about vouchers and a back-link to a purchase
. What I needed from this query: For all purchase
s who have is_paid=1
, count all vouchers of all the purchases with the same product id and group them by the product id.
What I need is: the above query translated as a Propel Criteria
API calls.
I am starting to work on this right away, but I will be happy if I could save some time.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奇怪的是,事实证明这非常简单:
寻呼机出了问题,但我花了 5 分钟才意识到让它计算如此重要的 Criteria 记录的方法很简单:
就是这样。
Curiously enough, it turned out to be very easy:
Had a trouble with the pager, but it took me 5 mins to realize that the way to make it count the records of such non-trivial Criteria was simply this:
That was it really.