select - how to convert count(*) and group by queries to yii and fetch data from it -
i want convert query in yii
select count(*) cnt, date(dt) tbl_log status=2 group date(dt)
and fetch data that. try command (dt
datetime field):
$criteria = new cdbcriteria(); $criteria->select = 'count(*) cnt, date(dt)'; $criteria->group = 'date(dt)'; $criteria->condition = 'status= 2'; $visit_per_day = $this->findall($criteria);
but no data fetch! wath can data?
probably see no data because need assign data model attributes doesn't exist.
$criteria = new cdbcriteria(); $criteria->select = 'count(*) cnt, date(dt) datevar'; $criteria->group = 'date(dt)'; $criteria->condition = 'status= 2'; $visit_per_day = $this->findall($criteria);
this means model must have attributes cnt , datevar in order show data. if need custom query check hearaman's answer.
Comments
Post a Comment