开发者

SQLCE: How to Count Datepart

开发者 https://www.devze.com 2023-04-01 19:00 出处:网络
For a long time I am struggling with the following subject: I want to count datepart values. I use SQL Compact Edition 4.0 and have no idea on how to get the following:

For a long time I am struggling with the following subject: I want to count datepart values. I use SQL Compact Edition 4.0 and have no idea on how to get the following:

select datepart(week, CreateDate)开发者_开发知识库 as Week, count(*) from tblOrders 
where CreateDate>'12 April 2010' and CreateDate<'25 June 2011'

This does not work obviously, but to give you an idea what I want to get as the result is: - 2 columns,

  • one called "week" - that would be a week number
  • in the second column - how many orders I had per week

Thanks in advance,

Pete


You'll need to add a Group By to make the query syntax correct.

select datepart(week, CreateDate) as Week, count(*) 
from tblOrders  where CreateDate>'12 April 2010' and CreateDate<'25 June 2011'
group by datepart(week, CreateDate)

Does that help?

0

精彩评论

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