如何在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`
最佳答案
这是对我有用的代码
$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");
关于mysql - 在Zend中从TABLE1中选择SELECT +(从TABLE1中的SELECT COUNT),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11981828/