【发布时间】:2012-04-14 13:54:38
【问题描述】:
我有一个与 cakephp 中复杂的查找条件相关的问题。 我有一个交易表,其中包含许多 transaction_item(是一个结构 product_id,date 的表),并且产品与供应商有多对多的联系。所以我对产品和供应商使用映射表,在 transaction_item 表中我使用外键进行交易。我的问题是如何在知道交易 ID 的情况下阅读供应商及其相关产品。
例子。
知道 transaction.id = 9;
我想要结果
Supplier id:1
Transaction Item 1
Transaction Item 2
Supplier id:2
Transaction Item 1
Transaction Item 3
在 SQL 中,我的查询是
SELECT
`map_table`.`supplier_id`,
`transaction_item_table`.`id`
FROM
`transaction_item_table`
INNER JOIN `map_table`
ON `transaction_item_table`.`id` = `map_table`.`product_id`
WHERE
`transaction_item_table`.`transaction_id` = 9
ORDER BY
`map_table`.`supplier_id`;
【问题讨论】:
-
为了将来,在发布您的问题时,如果您希望格式化看起来像没有 HTML 的类型,只需突出显示内容区域并单击编辑区域上方的打开/关闭花括号按钮以“格式化”而不是直接使用 HTML。