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 に答える