一起使用MIN和COUNT

时间:2013-07-16 20:53:52

标签: sql count min minimum

我有这张桌子:

CALLS

| Number | User_id | Duration | Date | Call_type |
  46534       2         65     1-1-13     5
  46535       3         55     1-1-13     4
  46537       1         47     1-2-13     5
  46538       7         87     3-4-13     7

我需要知道我有最少电话数量的日期或日期。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

SELECT Top 1 WITH TIES Number
    COUNT(Number),
    MIN(Date)
FROM <tablename>
GROUP BY Number
ORDER BY COUNT(Number)

答案 1 :(得分:0)

对日期进行分组并对计数进行排序,这会将最少呼叫的日期放在顶部:

select Date, count(*) as Calls
from CALLS
group by Date
order by count(*)