title: MySQL - Top 10 per day
body: <p>I am in need to generate top 10 by <code>PRESENCE</code> &amp; <code>LECTURE DURATION</code> from a table.</p>
  
  <p>I've tried a few things but with no luck. Here is the query as it stands now.</p>
  
  <p>Could I please get some guidance to get this right?</p>
  
  <pre><code>select 
          t1.EVE_DATE, 
          t1.CUSTID,
          SUM(t1.ATTENDENCE) as PRESENCE,
          TRUNCATE((AVG(t1.LECTURE_DUR))/(1000),2) as LECTURE_DUR
  from 
          MY_TABLE t1
              left join
          (
              select
                  CUSTID
              from
                  MY_TABLE t2
              where
                  t1.EVE_DATE = t2.EVE_DATE
              order by
                  t2.CUSTID
              limit 10
          ) t3
              on
          t1.CUSTID = t3.CUSTID
  where
          t1.SUBJECT= 'PHYSICS' 
          and t1.EVE_DATE &gt;= '2015-01-01'
          and t1.EVE_DATE &lt;= '2016-01-01'
          and t1.CUSTID &lt;&gt; ''
  group by
          t1.EVE_DATE,
          t1.CUSTID
  order by
          t1.EVE_DATE
  </code></pre>