Hi, my yii2 table goes in this way.
CREATE TABLE `ad_analytics` (
`id` int(90) NOT NULL,
`ad_id` int(90) NOT NULL,
`advertiser_id` int(90) NOT NULL,
`publisher_id` int(90) NOT NULL,
`visitor_ip` varchar(250) NOT NULL,
`type_ad` varchar(90) NOT NULL,
`impression` int(90) NOT NULL,
`view` int(90) NOT NULL,
`clicks` int(90) NOT NULL,
`date_event` date NOT NULL,
`placed_date` date NOT NULL,
`ending_date` date NOT NULL,
`cpc` int(60) NOT NULL,
`cpv` int(60) NOT NULL,
`cpi` int(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
And here is my grid view i want to display custom data in grid view for that the query is goes here.
<?= GridView::widget([
'dataProvider'=>new ActiveDataProvider([
'query' => Adanalytics::find()->
where(['advertiser_id' => Yii::$app->user->identity->id ]),
]),
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'ad_id',
'advertiser_id',
'publisher_id',
'visitor_ip',
//'type_ad',
//'impression',
//'view',
//'clicks',
//'date',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
And my query is as follows.
SELECT id, ad_id,MAX(impression) AS imp, MAX(view) AS vi, MAX(clicks) AS cl FROM ad_analytics GROUP BY ad_id, visitor_ip;
How to excecute this query in grid view and show the data accordingly?