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 7934837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:44:50+00:00 2026-06-03T21:44:50+00:00

i have a datatable in SQL server which contains 3 columns. 1st is DateTime,

  • 0

i have a datatable in SQL server which contains 3 columns. 1st is DateTime, and the 2nd & 3rd are both float. Im trying to calc the mean of the difference between columns 2 and 3 between a specific time interval, ie every 15 mins.

I managed to find the following example

SELECT * FROM dbo.data
WHERE CAST(DateTime AS TIME) BETWEEN '14:00' and '14:30'

but im unsure how to now calc the difference between the 2nd and 3rd column from the results of the above query. Id prefer to do this in t-sql unless someone believe performing this in c# would be more appropriate.

Thanks

EDIT

2010-01-04 14:30:00.0000000 1.44377 1.44386
2010-01-04 14:30:00.0000000 1.4438  1.44389
2010-01-04 14:30:00.0000000 1.44377 1.44386
2010-01-05 14:00:01.0000000 1.44258 1.44267

the results id like would be as follows

0.00009  ie 1.44386 - 1.44377
0.00009     1.44389 - 1.4438
0.00009     1.44386 - 1.44377
0.00009     1.44267 - 1.44258
  • 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-06-03T21:44:51+00:00Added an answer on June 3, 2026 at 9:44 pm

    If you just cast the date column as TIME you’ll end up with multiple dates, which I don’t think is your intent (see the results of the first query below to illustrate what I mean)

    DECLARE @Date DATETIME
    SELECT @Date = '05/15/2012 14:15'
    SELECT CAST(@Date AS TIME)
    SELECT @Date = '04/15/2012 14:15'
    SELECT CAST(@Date AS TIME)
    

    I think the query you want is the following:

    SELECT
        DATEADD(MINUTE, 15 * (DATEDIFF(MINUTE, 0, [Date]) / 15), 0), -- Assuming [Date] is the DATETIME column, this will give you 15 minute intervals
        AVG([Col2] - [Col3])
    FROM
        dbo.data
    GROUP BY
        DATEADD(MINUTE, 15 * (DATEDIFF(MINUTE, 0, [Date]) / 15), 0)
    

    If you want to search a specific time frame, just force it in your WHERE clause:

    SELECT
        AVG([Col2] - [Col3])
    FROM
        dbo.data
    WHERE
        [Date] BETWEEN '05/15/2012 14:00' AND '05/15/2012 14:30'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have WinForms app which stores data in SQL Server (2000, we are working
All, I have a Windows Service which queries a database (SQL Server) for some
In my SQL Server database schema I have a data table with a date
I have a DataTable with 3 columns (a,b,c) and a docx file with the
I have a user defined type, which is a datatable in an SqlServer database.
I am working on sql server monitoring product and i have database query that
I have a DataTable which is generated from .xls table. I would like to
I have a DataTable with an Id column, which is an identity column in
I have an SQL Server (2008 R2) based (C# WinForms) application that predominantly runs
I have a LINQ query in C# which runs on a datatable that is

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.