SELECT COUNT(DISTINCT(ccc)) AS ccc,COUNT(DISTINCT(bbb)) AS bbb FROM total WHERE user_id='$user_id' AND ADDDATE BETWEEN '$time[starttime]' AND '$endtime' GROUP BY aaa ORDER BY aaa DESC
sql语句如上,哪位大神指点一下。
SELECT COUNT(DISTINCT(ccc)) AS ccc,COUNT(DISTINCT(bbb)) AS bbb FROM total WHERE user_id='$user_id' AND ADDDATE BETWEEN '$time[starttime]' AND '$endtime' GROUP BY aaa ORDER BY aaa DESC
sql语句如上,哪位大神指点一下。
给你个我做过的例子:
db.runCommand({"distinct":"flyStat","key":"user","query":{"sys":"o2o","page":"index_groupBuy",$and:[{"date":{$gt:ISODate("2015-12-08T00:00:00.213Z")}},{"date":{$lt:ISODate("2015-12-09T00:00:00.213Z")}}]}}).values.length;
等价于:
select count(distinct user) from flyStat where sys=o2o and page=index_groupBuy and date>=151208 and date<=151209;
order很好写,你搜一下吧,group没写过
2 回答844 阅读
2 回答622 阅读
2 回答678 阅读
1 回答642 阅读
572 阅读
考虑使用MongoDB的aggregation:
1、COUNT(DISTINCT(ccc)) AS ccc,COUNT(DISTINCT(bbb)) AS bbb
$group+$sum
2、user_id='$user_id' AND ADDDATE BETWEEN '$time[starttime]' AND '$endtime'
$match
供参考。
Love MongoDB!Have fun!