Skip to content

Instantly share code, notes, and snippets.

@ferlyz05
Created December 31, 2013 04:14
Show Gist options
  • Save ferlyz05/8192535 to your computer and use it in GitHub Desktop.
Save ferlyz05/8192535 to your computer and use it in GitHub Desktop.
/* $sql = 'SELECT *
FROM pelanggan, (
SELECT id_pelanggan, COUNT( id ) AS total_promo, SUM( jumlah_resi ) AS jumlah_resi, SUM( total_nominal ) AS total_transaksi
FROM `promo`
GROUP BY id_pelanggan
) AS x
WHERE id = x.id_pelanggan'; */
$criteria = new CDbCriteria();
$criteria->compare('customer.nama',$this->nama,true);
$criteria->compare('customer.nmr_identitas',$this->nmr_identitas,true);
$criteria->with = array('promos'=>array(
'alias'=>'x',
'select'=>'id_pelanggan, COUNT( x.id ) AS id, SUM( x.jumlah_resi ) AS jumlah_resi, SUM( x.total_nominal ) AS total_nominal',
'group'=>'id_pelanggan'));
$criteria->alias = 'customer';
//$criteria->condition = 'customer.id = x.id_pelanggan';
return new CActiveDataProvider('Pelanggan', array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>20,
),
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment