SQLCE:如何计算日期部分

发布于 2024-12-03 01:03:42 字数 371 浏览 0 评论 0原文

很长一段时间我都在努力解决以下主题:我想计算日期部分值。我使用 SQL Compact Edition 4.0,不知道如何获得以下内容:

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

这显然不起作用,但为了让您了解我想要得到的结果是: - 2 列,

  • 其中一列称为“周” - 这将是第二列中的周数
  • - 我每周有多少订单

提前致谢,

Pete

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-12-10 01:03:43

您需要添加 Group By 以使查询语法正确。

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

这有帮助吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文