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

  • Home
  • SEARCH
  • 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 580179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:26:43+00:00 2026-05-13T14:26:43+00:00

I have a logging table used for device heartbeats. I have these network devices

  • 0

I have a logging table used for device “heartbeats”. I have these network devices that check-in/heartbeat with the server every 10 minutes. We are wanting statistics on when they miss their scheduled check-in time. I have a query that can do this on a per-device basis, but I need it to be modified to handle across all devices.

The heartbeat table looks like this:

CREATE TABLE [dbo].[DeviceHeartbeat](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [DeviceId] [int] NULL,
    [CheckinTime] [datetime] NULL,
    [Runtime] [int] NULL,
PRIMARY KEY CLUSTERED 
([Id] ASC)) ON [PRIMARY]

Device checks into the server, the server adds a row to this table with its Id, the CheckinTime and the device’s runtime (a hardware value sent by the device).
The query I have currently looks like this:

WITH t AS
(
  SELECT Checkintime, rn = ROW_NUMBER() OVER (ORDER BY Checkintime)
  FROM DeviceHeartbeat
  WHERE DeviceId = 1112
),
x AS
(
  SELECT d = DATEDIFF(MINUTE, t1.Checkintime, t2.Checkintime)
  FROM t AS t1
  INNER JOIN t AS t2
  ON t1.rn = t2.rn - 1
),
y AS
(
  SELECT stats = CASE WHEN d < 10 THEN ' < 10 '
    WHEN d BETWEEN 10 AND 11 THEN '10 - 11 '
    WHEN d BETWEEN 11 AND 12 THEN '11 - 12 '
    ELSE '+12 ' END + ' minutes:'
  FROM x
)
SELECT stats, COUNT(*) FROM y GROUP BY stats;

This query is limited to a single specified device. Example results look like this:

stats                  
----------------- ---- 
 < 10  minutes:   1536
10 - 11  minutes: 425
11 - 12  minutes: 952
+12  minutes:     160

Ideally, I’m only concerned with check-ins greater than 12 minutes. So, what I was wanting was a list of devices who have check-ins greater than 12 minutes, ordered by their counts. This will allow me to see the top 10 or 20 devices that have greater than 12 minute check-in times, alerting me to problem devices.
Something like:

DeviceId   CheckinsOver12Mins
---------- -------------------
1112       160
1108       152
15         114
106        86

Suggestions?

  • 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-13T14:26:44+00:00Added an answer on May 13, 2026 at 2:26 pm

    Try this:

    WITH t AS
    (
      SELECT Checkintime, DeviceID, rn = ROW_NUMBER() OVER (ORDER BY DeviceID, Checkintime)
      FROM DeviceHeartbeat
    ),
    x AS
    (
      SELECT t1.deviceID, d = DATEDIFF(MINUTE, t1.Checkintime, t2.Checkintime)
      FROM t AS t1
      INNER JOIN t AS t2
      ON t1.rn = t2.rn - 1 and t1.DeviceID = t2.DeviceID
    ),
    y AS
    (
      SELECT deviceID
      FROM x
      WHERE d > 12
    )
    select deviceID, count(deviceID) as [Checkins over 12 mins] FROM y GROUP BY deviceID
    

    Note: Don’t have test data — did not test, might have typos.

    It should be the y CTE could be removed and changed to making it a smaller query:

    select deviceID, count(deviceID) as [Checkins over 12 mins] 
    FROM x 
    GROUP BY deviceID
    HAVING d > 12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might show us your global.asax.cs routes. Avoid using ../… May 13, 2026 at 8:30 pm
  • Editorial Team
    Editorial Team added an answer You're talking about IPC - Interprocess Communication. There are many… May 13, 2026 at 8:30 pm
  • Editorial Team
    Editorial Team added an answer Did you add a Html.ValidationSummary() to your page? May 13, 2026 at 8:30 pm

Related Questions

I have a logging table that stores the user id, date/time, table name, record
I have a nant script that ... 1. takes the content of disc-file 2.
I have 2 tables in my database that I'm trying to create Linq2Sql entities
I have a database that I used specifically for logging actions of users. The
Recently, I took it upon myself to try and learn OO programming. It has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.