简体   繁体   中英

SQLCE: How to Count Datepart

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM