如何在Zend DB中进行此查询?

时间:2013-06-14 19:55:15

标签: sql zend-framework zend-db

我正在尝试让Zend DB生成以下查询:

SELECT DISTINCT
    US.nombre AS Cliente,
    VE.id_venta,
    VE.fecha,
    VE.total,
    ve.observacion
FROM
    usuarios AS US,
    ventas AS VE

我已经尝试过以下代码,但它不起作用:

$select = $this->select();
$select->from(array('VE' => 'ventas'), array('id_venta', 'fecha', 'total', 'observacion'))
       ->from(array('US' => 'usuarios'),'ve.id_usuario');

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西:

$select = $this->select();
$select->from(array('US' => 'usuarios'), array('US.nombre as Cliente'))
       ->from(array('VE' => 'ventas'), array('VE.id_venta', 'VE.fecha', 'VE.total', 'VE.observacion'));

这给了我以下输出:

SELECT `US`.`nombre` AS `Cliente`, `VE`.`id_venta`, `VE`.`fecha`, `VE`.`total`, `VE`.`observacion` FROM `usuarios` AS `US` INNER JOIN `ventas` AS `VE`