SELECT tu.user_name, NVL(SUM(fds.MONEY), 0) MONEY
  FROM F_DRUG_SALES fds
 INNER JOIN T_USER_PROPERTY tu
    ON fds.BILLING_PERSON_ID = tu.ID
 INNER JOIN T_DATES td
    ON fds.DATE_ID = td.ID
 WHERE 1 = 1
   AND fds.BILLING_OFFICE_ID IN (13287)
   AND td.CAL_DATE >= '2017-05-01'
   AND td.CAL_DATE <= '2017-05-31'
 GROUP BY tu.user_name
 ORDER BY NVL(SUM(fds.MONEY), 0) DESC
 WHERE ROWNUM <= 10

解决方案 »

  1.   

    稍微改下就可以了select tu.user_name, nvl(sum(fds.money), 0) money
      from f_drug_sales fds
     inner join t_user_property tu
        on fds.billing_person_id = tu.id
     inner join t_dates td
        on fds.date_id = td.id
     where fds.billing_office_id in (13287)
       and td.cal_date >= '2017-05-01'
       and td.cal_date <= '2017-05-31'
       and rownum <= 10
     group by tu.user_name
     order by nvl(sum(fds.money), 0) desc 
      

  2.   

    调整下:select user_name,money
      from(select tu.user_name, nvl(sum(fds.money), 0) money
         from f_drug_sales fds
        inner join t_user_property tu
       on fds.billing_person_id = tu.id
        inner join t_dates td
       on fds.date_id = td.id
        where fds.billing_office_id in (13287)
          and td.cal_date >= '2017-05-01'
          and td.cal_date <= '2017-05-31'
     group by tu.user_name
     order by nvl(sum(fds.money), 0) desc
     )
    where rownum <= 10