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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:23:37+00:00 2026-05-22T15:23:37+00:00

My current version is : SELECT DT, AVG(DP_H2O) AS Tx, (SELECT AVG(Abs_P) / 1000000

  • 0

My current version is :

SELECT     DT, AVG(DP_H2O) AS Tx,
           (SELECT    AVG(Abs_P) / 1000000 AS expr1
           FROM       dbo.BACS_MinuteFlow_1
           WHERE      (DT =
                                     (SELECT     MAX(DT) AS Expr1
                                       FROM      dbo.BACS_MinuteFlow_1
                                       WHERE     DT <= dbo.BACS_KongPrima.DT ))
          GROUP BY DT) AS Px
  FROM    dbo.BACS_KongPrima
  GROUP BY DT

but it works very slow.

basically in inner select I’m selecting maximum near time to my time, then group by this nearest time.

Is there possible optimizations ? Maybe I can join it somehow , but the trouble I’m not sure how to group by this nearest date.

Thank you

  • 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-22T15:23:38+00:00Added an answer on May 22, 2026 at 3:23 pm

    You could try to rearrange it to use the code below using a cross apply. Am not sure if this will improve performance but generally I try to avoid at all costs using a query on a specific column and SQL Server is pretty good at optimising the Apply statement.

    WITH  Bacs_MinuteFlow_1  (Abs_P ,DT ) AS
    (SELECT 5.3,'2011/10/10'
        UNION SELECT 6.2,'2011/10/10'
        UNION SELECT 7.8,'2011/10/10'
        UNION SELECT 5.0,'2011/03/10'
        UNION SELECT 4.3,'2011/03/10'),
    BACS_KongPrima (DP_H2O ,DT)AS
    (SELECT 2.3,'2011/10/15'
        UNION SELECT 2.6,'2011/10/15'
        UNION SELECT 10.2,'2011/03/15')
    
    SELECT DT, AVG(DP_H2O) AS Tx,
           a.Px
    
    FROM    BACS_KongPrima
    CROSS APPLY  
    (
    SELECT AVG(Abs_P) / 1000000 AS Px 
    FROM BACS_MinuteFlow_1 
    WHERE DT =
        (SELECT     MAX(DT) AS maxdt 
         FROM      BACS_MinuteFlow_1
         WHERE     DT <= BACS_KongPrima.DT
        )
    ) a
    GROUP BY DT,a.Px
    

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example version of my current SQL query: SELECT DISTINCT files.* FROM
I have downloaded the current version of Db4Objects (7.4) and installed it. It appears
I need to upgrade my current version of DNN this week. I am currently
Is there a way to identify the current version of IIS / using NSIS
How is performance in the current version (4.7) of Accurev ? time to checkout
How do you check the current version of eclipse that I am currently running?
I'm not clear on the differences between the current version of Ruby (1.8) and
Anyone familiar with specific security issues in the current version of DotNetNuke? (I've already
I have a web application that uses the current version of JQuery that needs
I need to find some strings that the current version of Windows is using.

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.