如何按日期分组而不是按时间分组? [英] How to group by date but not time?

查看:94
本文介绍了如何按日期分组而不是按时间分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


希望对任何SQL专家都很简单。在Access查询中,如何按日期字段进行分组,而不会按时间分解我的数据?换句话说,我只想要每天计数,而不是每秒计数。


我正在使用Access 2003,但我怀疑在这种情况下是否重要。


目前我只是使用一个功能(见下文)去除日期,但我认为这非常低效。


我尝试了一些搜索,但这是一个有太多信息的案例。就在TSDN内部,有几十个帖子提到按日期分组,但它们似乎主要与原因或为什么不相关,不同的情况应按日期分组,等等。


到目前为止我尝试过:

Hi all.

Hopefully a simple one for any SQL guru. In an Access query, how can I group by a date field, without having my data broken down by time? In other words, I just want a count per day, not per second or whatever.

I''m using Access 2003, but I doubt it matters in this case.

At present I am just using a function (see below) to strip off the date, but I consider this terribly inefficient.

I did try some searching, but this is one case where there''s too much info available. Just within TSDN there are dozens upon dozens of postings mentioning grouping by date, but they seem to mostly relate to reasons why or why not, different situations where one should group by dates, and so on.

What I''ve tried so far:

  1. 首先我尝试将GROUP BY列设置为格式(DateField,dd / mm) / yyyy")这很有效,但显然按错误顺序排序。
  2. 目前我的GROUP BY列设置为 DateOnly(DateField),我有写的...
  1. First I tried setting the GROUP BY column to Format(DateField,"dd/mm/yyyy") and this worked, but obviously sorted in the wrong sequence.
  2. Currently my GROUP BY column is set to DateOnly(DateField), and I have written...
展开 | 选择 < span class =codeDivider> | Wrap | 行号

推荐答案

如果你已经对日期字段进行了分组,那么现在你的数据格式很短


下一步是订购,您是否尝试过指定列号?


例如


选择格式(f1," ;短日期)

来自mytable

group by format(f1,short date)

order by 1
If u have grouped the date field, u now have your data in short format

Next thing is ordering, have u tried specifying column numbers?

eg

select format(f1,"short date")
from mytable
group by format(f1,"short date")
order by 1


如果GROUP BY 格式(DateField,dd / mm / yyyy)和ORDER BY DateField 这可以解决您的问题吗? />
Mary
If you GROUP BY Format(DateField,"dd/mm/yyyy") and ORDER BY DateField does this solve your problem?
Mary



如果你是GROUP BY 格式(DateField," dd / mm / yyyy") 和ORDER BY DateField 这可以解决您的问题吗?
If you GROUP BY Format(DateField,"dd/mm/yyyy") and ORDER BY DateField does this solve your problem?



我会试一试,然后通知你。

I''ll try it, and let you know.


这篇关于如何按日期分组而不是按时间分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆