search

Home  >  Q&A  >  body text

mysql - Which master can write this SQL sentence using mongodb?

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

The sql statement is as above, can anyone give me some advice?

phpcn_u1582phpcn_u15822729 days ago1217

reply all(1)I'll reply

  • typecho

    typecho2017-06-30 09:56:02

    考虑使用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!

    reply
    0
  • Cancelreply