//采用thinkphp模式进行的子查询算法
$model = M();
$subQuery = $model->field('piwik_source')->table('think_user_cart_log')->group('piwik_cookie')->where($where)->order('piwik_cookie')->buildSql();
$vlist = $model->field('count(t.piwik_source) as num, t.piwik_source')->table($subQuery.' as t')->group('piwik_source')->order("num desc")->select();
echo $model->getLastSQL();
var_dump($vlist);
// echo $subQuery;
exit;
//强制手写sql语句的查询方式
$sql = 'SELECT count(t.piwik_source) as num, t.piwik_source FROM(
select piwik_source from `think_user_cart_log` WHERE piwik_cookie IS NOT NULL OR piwik_cookie !=\'\' group by piwik_cookie
) as t group by t.piwik_source
order by num desc';
$voList = M()->query($sql);
var_dump($voList);exit;