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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:49:56+00:00 2026-05-28T16:49:56+00:00

I have a table of data for a particular stock that contains every single

  • 0

I have a table of data for a particular stock that contains every single transaction going back a few years. I want to group this data on a per-day basis, so that I can see things like the daily volume, etc.

The best way I have come up with so far is:

select 
datepart(year, date),
datepart(month, date),
datepart(day, date), 
sum(volume) from hi 
group by 
datepart(year, date),
datepart(month, date),
datepart(day, date)
order by
datepart(year, date),
datepart(month, date),
datepart(day, date)

My SQL is somewhat limited, so I’m wondering if there’s a more efficient way to do this?

  • 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-28T16:49:57+00:00Added an answer on May 28, 2026 at 4:49 pm
    SELECT DateAdd(dd, sub.DayCount, 0) as TheDate, SUM(sub.Volume)
    FROM
    (SELECT DateDiff(dd, 0, date) as DayCount, Volume FROM hi)
    as Sub
    GROUP BY Sub.DayCount
    ORDER BY Sub.DayCount
    

    As far as efficiency goes, both queries must read the whole table once. They incur the same IO. You should messure IO with SET STATISTICS IO ON to see if that’s a problem.

    Since it seems that IO is the real issue, one option is to create an index which includes both Volume, DayCount (and no other columns).

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

Sidebar

Related Questions

I have table which contains data along with created on date. I want to
I have an employee table, with the following data. For a particular manager, i
I have table of data that is sorted as follows: Item | Sample |
I have a table of data that I need to dynamically add a column
I have a table of data which represents a series of events that persons
I have a table of data with survey results, and I want to do
Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
I have a data table that is initially empty and is populated after a
I have a data table containing multiple columns and one column that stores somewhat
I have a data.table which contains multiple columns, which is well represented by the

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.