Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6044313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:59:50+00:00 2026-05-23T06:59:50+00:00

Given the tables below, what is the best approach to (in both server-flavors): Group

  • 0

Given the tables below, what is the best approach to (in both server-flavors):

Group all rows within a minute/hour/day and get the maximum column ‘CounterC’ ?

Example: Between ‘now’ and ‘now’ – 1 day, get Max(CounterC) for each hour.
Example2: Between ‘now’ and ‘now’ – 30 days, get Max(CounterC) for each day.

Obviously the rows have to be grouped, but how?

MS SQL

CREATE TABLE [dbo].[DE0000000D102D1D](
[index] [bigint] IDENTITY(1,1) NOT NULL,
[TimeStamp] [datetime] NOT NULL,
[CounterA] [bigint] NOT NULL,
[CounterB] [bigint] NOT NULL,
[CounterC] [bigint] NOT NULL,
[CounterD] [bigint] NOT NULL,
)

MySQL

CREATE TABLE `de0000000d102d1d` (
 `index` bigint(20) NOT NULL AUTO_INCREMENT,
 `TimeStamp` datetime NOT NULL,
 `CounterA` bigint(20) NOT NULL,
 `CounterB` bigint(20) NOT NULL,
 `CounterC` bigint(20) NOT NULL,
 `CounterD` bigint(20) NOT NULL,
 PRIMARY KEY (`index`)
)

Some example data:

index  TimeStamp                CounterA  CounterB  CounterC   CounterD
-----  -----------------------  --------  --------  ---------  --------
1      2011-03-07 14:25:32.000  0         1         347406352  916
2      2011-03-07 14:26:32.000  0         1         347407169  916
3      2011-03-07 14:27:32.000  0         1         347407978  916
4      2011-03-07 14:28:31.000  0         1         347408617  916
5      2011-03-07 14:29:31.000  0         1         347409087  916
6      2011-03-07 14:30:30.000  0         1         347409557  916
7      2011-03-07 14:31:09.000  0         1         347409845  916

Thanks in advance!

Edit: It is actually Max(CounterC) I want for each interval, not the sum.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:59:51+00:00Added an answer on May 23, 2026 at 6:59 am

    For SQL Server

    -- Last 30 days grouped by day
    select dateadd(day, datediff(day, 0, D.[TimeStamp]), 0) as [day], 
           max(D.CounterC) as MaxC
    from DE0000000D102D1D as D
    where D.[TimeStamp] between dateadd(d, -30, getdate()) and getdate()
    group by dateadd(day, datediff(day, 0, D.[TimeStamp]), 0)
    
    -- Last day grouped by the hour
    select dateadd(hour, datediff(hour, 0, D.[TimeStamp]), 0) as [Hour], 
           max(D.CounterC) as MaxC
    from DE0000000D102D1D as D
    where D.[TimeStamp] between dateadd(d, -1, getdate()) and getdate()
    group by dateadd(hour, datediff(hour, 0, D.[TimeStamp]), 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the use of the below given tables in Joomla Database? jos_core_acl_aro jos_core_acl_aro_groups
I have 10 tables in my database(MySQL). two of them is given below tbl_state
A query (see below) that extracts climate data from weather stations within a given
Considering the tables below, what is the best way to only return the team
Given the one-table design given below how would the following best be queried The
Given the Below Tables. How do I get the Distinct name given the other
Given a table like the one below, what would be the best way to
Given the following html table and script shown below I am having a problem
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.