1

如何在 Zend 中编写此查询

SELECT COUNT( 1 ) AS  `NoOfQueries` , DATE( CONVERT_TZ( FROM_UNIXTIME( poocher.cdate,  '%Y-%m-%d %T' ) ,  '-9:30',  '+00:00' ) ) AS  `Dat` , COUNT( 1 ) + ( 
    SELECT COUNT( 1 ) 
    FROM tblsmsuser poocherb4
    WHERE DATE( CONVERT_TZ( FROM_UNIXTIME( poocherb4.cdate,  '%Y-%m-%d %T' ) ,  '-9:30',  '+00:00' ) ) <= DATE_SUB(  `Dat` , INTERVAL 1 
    DAY ) ) AS cumulative_sum
FROM tblsmsuser poocher
GROUP BY  `Dat`

我试过的是

$this->select = new Zend_Db_Select($this->db);
$selctSub = $this->select->from("tblsmsuser",array("count(1)"))->where("DATE( CONVERT_TZ( FROM_UNIXTIME( tblsmsuser.cdate,  '%Y-%m-%d %T' ) ,  '-9:30',  '+00:00' ) ) <= DATE_SUB(  Dat , INTERVAL 1 DAY )");
echo $select_query_ans = $this->select->from(array("poocher" =>"tblsmsuser"),array("NoOfQueries"=>"count(1)","Dat"=>"DATE( CONVERT_TZ( FROM_UNIXTIME( poocher.cdate,'%Y-%m-%d %T' ),'-9:30','+00:00' ) )","cumulative_sum"=>"count(1) + (".$selctSub.")"))->group("Dat");

输出

SELECT count(1) AS `NoOfQueries`, DATE( CONVERT_TZ( FROM_UNIXTIME( poocher.cdate,'%Y-%m-%d %T' ),'-9:30','+00:00' ) ) AS `Dat`, count(1) + (SELECT count(1) AS `NoOfQueriesb4` FROM `tblsmsuser` AS ```poocherb4`` WHERE (DATE( CONVERT_TZ( FROM_UNIXTIME( poocherb4.cdate, '%Y-%m-%d %T' ) , '-9:30', '+00:00' ) ) <= DATE_SUB( Dat , INTERVAL 1 DAY )))`, count(1) AS `NoOfQueriesb4` FROM `tblsmsuser` AS `poocher` INNER JOIN `tblsmsuser` AS `` WHERE (DATE( CONVERT_TZ( FROM_UNIXTIME( poocherb4.cdate, '%Y-%m-%d %T' ) , '-9:30', '+00:00' ) ) <= DATE_SUB( Dat , INTERVAL 1 DAY )) GROUP BY `Dat` 
4

1 回答 1

0

这是对我有用的代码

    $this->select = new Zend_Db_Select($this->db);
    $selctSub = $this->select->from("tblsmsuser",array("count(1)"))->where("DATE( CONVERT_TZ( FROM_UNIXTIME( tblsmsuser.cdate,  '%Y-%m-%d %T' ) ,  '-9:30',  '+00:00' ) ) <= DATE_SUB(  Dat , INTERVAL 1 DAY )");
    $this->select = new Zend_Db_Select($this->db);  //ADDED line
    echo $select_query_ans = $this->select->from(array("poocher" =>"tblsmsuser"),array("NoOfQueries"=>"count(1)","Dat"=>"DATE( CONVERT_TZ( FROM_UNIXTIME( poocher.cdate,'%Y-%m-%d %T' ),'-9:30','+00:00' ) )","cumulative_sum"=>"count(1) + (".$selctSub.")"))->group("Dat");
于 2012-08-17T04:14:55.653 回答