我有一个 MySQL 的 SQL 查询,它给了我正确的结果。但是,我在使用 DQL 将其转换为 Doctrine 查询时遇到了问题。
SELECT Sum(s) AS s
FROM (SELECT DISTINCT oder.id AS m,
o_t.restaurants_id,
o_t.value AS s
FROM orders AS oder
INNER JOIN order_total AS o_t
ON oder.id = o_t.orders_id
INNER JOIN order_status AS o_s
ON oder.id = o_s.orders_id
WHERE o_s.status = 1
AND o_t.code = 'total') a
我正在尝试以下操作:
$query = Doctrine_Query::create()
->select('sum(s) as s')
->addSelect('DISTINCT order.id,o_t.value')
->from('orders as order')
->leftJoin('order.order_total as o_t')
->leftJoin('order.order_status as o_s_i')
->where('o_s_i.status = '.order_status::ORDER_COMPLETE)
->andWhere('o_t.code = "total"')->getSqlQuery();
返回:
SELECT DISTINCT o.id AS o__id,
o2.id AS o2__id,
o2.value AS o2__value,
Sum(s) AS o__0
FROM orders o
LEFT JOIN order_total o2
ON o.id = o2.orders_id
LEFT JOIN order_status o3
ON o.id = o3.orders_id
WHERE ( o3.status = 1
AND o2.code = "total" )
任何的想法?