English 中文(简体)
单位:分钟或小时
原标题:Group By n Minutes or Hours

我需要用一个用户确定的时间段查询一个表和小组记录,这些时间可以是分钟或小时的分类。 我们得出的一个假设是,任何选定的时间都始于12:00AM(如果是这样的话)。 换言之,如果用户选择按15分钟分组记录,我们就不允许他们说,从12:07AM开始每15分钟就进行分组。 我们自动假定/使用12:00AM作为分组的起点。 任何其他时间段。

我是否需要为此建立自己的职能? 我对业绩并不过分关切,因为我将利用其他方法/限制,试图把业绩问题放在一旁。

我的看法是:

timeentry
--entryid         (autonumber)
--begindatetime   (datetime)
--enddatetime     (datetime)

如果我使用某种职能,我就不认为此事,但我确实计划把我的集团建立在开始和忽视结束时间的基础之上。

使用MS Access的Im,但我像我的解决方案一样,尽可能与服务器和MySQL兼容。 然而,我目前的主要重点只是获得管理服务。

问题回答

在我看来,分部分职能在这方面可能是有益的。

你的代码将根据用户迄今的选择(我假定你要把问询限制在单一日期的起算值)、时间单位和群体间歇性的基础上,形成一份电子数据表。

时间为14,2011年,时间单位为分钟,间隔为15分钟。

SELECT
    Partition(elapsed,0,1440,15) AS time_block,
    q.id,
    q.begindatetime
FROM
    [SELECT
        t.id,
        t.begindatetime,
        TimeValue(t.begindatetime) * 1440 AS elapsed
    FROM tblHK1 AS t
    WHERE
        t.begindatetime>=#2011-06-14#
        And t.begindatetime<#2011-06-15#
    ]. AS q
ORDER BY q.begindatetime;

但并不确定你会这么多。 这里的一些样本产出:

time_block id begindatetime
  60:  74   1 6/14/2011 1:06:05 AM
 555: 569   3 6/14/2011 9:15:00 AM
1395:1409   4 6/14/2011 11:15:00 PM

时间段一栏对用户非常友好。

我不相信你想要什么,但这里有一个想法:

SELECT DateDiff("n",CDate("00:00"),[BeginDateTime])15 AS No15s, 
       (DateDiff("n",CDate("00:00"),[BeginDateTime])15)*15 AS NoMins,
       Count(Table1.BeginDateTime) AS [Count]
FROM Table1
GROUP BY DateDiff("n",CDate("00:00"),[BeginDateTime])15, 
        (DateDiff("n",CDate("00:00"),[BeginDateTime])15)*15;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签