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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:42:48+00:00 2026-05-22T21:42:48+00:00

I have a query to aggregate (compress) data from 1 min to any other

  • 0

I have a query to aggregate (compress) data from 1 min to any other time frame, and it works perfectly.

Use StockDataFromSella;
DECLARE @D1 DateTime 
DECLARE @D2 DateTime 
DECLARE @Interval FLOAT 

SET @D1  = '2008-09-21T09:00:00.000' 
SET @D2  = '2010-10-20T17:30:00.000'
SET @Interval = 15 

;WITH  
L0 AS (SELECT 1 AS c UNION ALL SELECT 1), 
L1 AS (SELECT 1 AS c FROM L0 A CROSS JOIN L0 B), 
L2 AS (SELECT 1 AS c FROM L1 A CROSS JOIN L1 B), 
L3 AS (SELECT 1 AS c FROM L2 A CROSS JOIN L2 B), 
L4 AS (SELECT 1 AS c FROM L3 A CROSS JOIN L3 B), 
Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS i FROM L4), 
Ranges AS( 
SELECT  
      DATEADD(MINUTE,@Interval*(i-1),@D1) AS StartRange, 
      DATEADD(MINUTE,@Interval*i,@D1) AS NextRange 
FROM Nums where i <= 1+CEILING(DATEDIFF(MINUTE,@D1,@D2)/@Interval)) 
,cte AS ( 
SELECT  
     *  
     ,ROW_NUMBER() OVER (PARTITION BY Simbolo,r.StartRange ORDER BY [DataOra])      AS RN_ASC  
     ,ROW_NUMBER() OVER (PARTITION BY Simbolo,r.StartRange ORDER BY [DataOra] DESC) AS RN_DESC 
FROM Ranges r 
JOIN dbo.tbl1MinENI p  ON p.[DataOra] >= r.StartRange and p.[DataOra] < r.NextRange ) 
SELECT  
      Simbolo, 
      MAX(CASE WHEN RN_ASC=1 THEN [DataOra] END) AS DataOra, 
      MAX(CASE WHEN RN_ASC=1 THEN [Apertura] END) AS [Apertura], 
      MAX(Massimo) Massimo, 
      MIN(Minimo)  Minimo, 
      MAX(CASE WHEN RN_DESC=1 THEN [Chiusura] END) AS [Chiusura],
      SUM(Volume) Volume
      /*MAX(CASE WHEN RN_DESC=1 THEN [DataOra] END) AS ChiusuraDataOra*/
FROM cte 
GROUP BY Simbolo,StartRange 
ORDER BY DataOra

I would like to split second column DataOra(DateTime) into two diferent columns, one for Date (if possibile in dd/mm/yyyy format) and the second for Time only.
Any help very appreciated, thanks.
Alberto

  • 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-22T21:42:49+00:00Added an answer on May 22, 2026 at 9:42 pm

    The easiest way to get these values would be to use CONVERT. SQL Server has some built-in date formatting when you convert a Date.

     CONVERT(VARCHAR, MAX(CASE WHEN RN_ASC=1 THEN [DataOra] END), 103) AS DataOraDate, 
     CONVERT(VARCHAR, MAX(CASE WHEN RN_ASC=1 THEN [DataOra] END), 114) AS DataOraTime, 
    

    The two codes (103 and 114) correspond to the formats that you want. See http://msdn.microsoft.com/en-us/library/ms187928.aspx for more details about those and the other formats you can convert to.

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

Sidebar

Related Questions

I have several query results that use one or more aggregate functions and a
I have a query: select min(timestamp) from table This table has 60+million rows, and
I have a query that uses a lot of aggregate functions to build data
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I am using in C# MYsql .I have query that works if I run
I have a query on my database as such: SELECT * FROM expenses WHERE
I have a query that I'm executing from a .NET application to a SQL
So I have a query that is a Top Nth aggregate query, and I
In short: Given an aggregate query (one with Max, Min, Count, etc) in NHibernate,
I have this update query: UPDATE aggregate_usage_input t JOIN (SELECT t2.id FROM aggregate_usage_input t2

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.