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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:53+00:00 2026-05-23T20:10:53+00:00

Sql: select distinct DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as Date, (select count(*) from Raw_Mats

  • 0

Sql:

select distinct DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as Date,
(select count(*) from Raw_Mats A where DateAdd(Day, DateDiff(Day, 0, A.Receive_date), 0)=DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0)) as Total,
(select count(*) from Raw_Mats B where DateAdd(Day, DateDiff(Day, 0, B.Receive_date), 0)=DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) and B.status='Solved') as Delivered,
(select count(*) from Raw_Mats C where DateAdd(Day, DateDiff(Day, 0, C.Receive_date), 0)=DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) and C.status='Pending') as UnDelivered
from Raw_Mats m where m.Receive_date between '2011-07-01' and '2011-07-21'

How to increase the performance of the above query. It is taking 44 secs . wanna make it less than 10 secs

Thanks

  • 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-23T20:10:54+00:00Added an answer on May 23, 2026 at 8:10 pm

    Do you have an index on both Receive_date and status? (not an index on each, combined)

    Also:

    • You have have 4 touches in the table which means the query will scale at least O(4n).
      By using COUNT(CASE) you can remove Delivered and UnDelivered subqueries
    • The simple count subquery isn’t needed either
    • You need GROUP BY. YOur DISTINCT is a work around for that
    • BETWEEN is >= and <= which isn’t the usually correct for dates with times

    I’ve used a subquery here for clarity but it doesn’t matter:

    select
       DateOnly as Date,
       COUNT(*) AS Total,
       COUNT(CASE WHEN status='Solved' THEN 1 END) AS Delivered,
       COUNT(CASE WHEN status='Pending' THEN 1 END) AS UnDelivered
    from
       (
       SELECT
           DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as DateOnly,
           status
       FROM
          Raw_Mats
       WHERE
          Receive_date >= '2011-07-01' AND Receive_date < '2011-07-21'
       ) T
     GROUP BY
       DateOnly
    

    Edit, without subquery.

    I started with a subquery because I thought it’s be more complex than expected and didn’t bother taking it out…

    select
       DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as Date,
       COUNT(*) AS Total,
       COUNT(CASE WHEN status='Solved' THEN 1 END) AS Delivered,
       COUNT(CASE WHEN status='Pending' THEN 1 END) AS UnDelivered
    from
       Raw_Mats
    WHERE
       Receive_date >= '2011-07-01' AND Receive_date < '2011-07-21'
    GROUP BY
       DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
Here's my SQL statement: SELECT DISTINCT a.* FROM OWU_Nomination as a, Merchants as b
I have this SQL Server query SELECT count(distinct [IP]) as GlobalUniqueIPcount, --RangeUniqueIPcount (SELECT count(distinct
Trying to go from here this SQL: SELECT DISTINCT iss.ID FROM Issue AS iss
Getting ORA-00918: column ambiguously defined: running this SQL: SELECT * FROM (SELECT DISTINCT(coaches.id), people.*,
Here is my SQL Statement which is not returning DISTINCT Thread Titles. SELECT DISTINCT
SQL: SELECT u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault FROM universe u LEFT JOIN history h
The following SQL: SELECT notes + 'SomeText' FROM NotesTable a Give the error: The
The following SQL SELECT * FROM customers converted to this in LINQ var customers

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.