开发者

sql query count multiple rows between two dates

开发者 https://www.devze.com 2023-02-15 19:13 出处:网络
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:

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

精彩评论

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