开发者

sql query count multiple rows between two dates

Greetings, I am trying to build a query that will provide me with the totals of all records (some records are recurring) between two dates. I am stuck at the following query:

SELECT DISTINCT Country, COUNT(Country) as Count, Date 
From Da开发者_StackOverflowtaSet 
GROUP BY Country, Date 
ORDER BY Country HAVING Date>'1/1/2000'

Thanks in advance.


  SELECT DISTINCT Country, COUNT (Country) AS COUNT
    FROM DataSet
   WHERE Date BETWEEN '01-01-2010' AND '01-01-2011'
GROUP BY Country
ORDER BY Country

You should not group by date because you'll get for every date a row


SELECT Country, COUNT(DISTINCT Country) as "Count"
FROM DataSet  GROUP BY Country, Date
HAVING Date>'1/1/2000';

because HAVING are not set with order by ok coorect it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜