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

The Archive Base Latest Questions

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

UPDATE: Thanks to Sifu Bill’s advice I have amended the SQL query. Now it

  • 0

UPDATE: Thanks to Sifu Bill’s advice I have amended the SQL query. Now it returns the correct number of distinct assets (five).

Is it possible to rewrite the following subquery as a JOIN?

SELECT TOP 100 PERCENT Asset_ID, work_order_id, status_id,
downtime_hours, date_completed
FROM dbo.mtvw_wo_reason1
WHERE (Asset_ID IN
(SELECT TOP 5 Asset_ID from mtvw_wo_reason1
WHERE (Date_Completed BETWEEN '1-Oct-2009' AND '31-Oct-2009')
GROUP BY Asset_ID
ORDER BY SUM(Downtime_hours) DESC))

The output follows:

Asset_ID work_order_id status_id downtime_hours Date_Completed

SFM2019 2009-724    Completed   .5000   2009-09-01 17:55:09.000
SFM2019 2009-761    Completed   .5000   2009-09-15 09:03:39.000
SFM2019 2009-828    Completed   8.0000  2009-10-02 00:00:00.000
SFM2043 2009-683    Completed   .5000   2009-08-14 00:00:00.000
SFM2043 2009-734    Completed   1.0000  2009-09-05 00:54:33.000
SFM2043 2009-741    Completed   1.0000  2009-09-08 17:05:09.000
SFM2043 2009-756    Completed   .5000   2009-09-14 07:56:41.000
SFM2043 2009-792    Completed   1.0000  2009-09-22 00:00:00.000
SFM2043 2009-826    Completed   8.0000  2009-10-03 02:00:19.130
SFM2043 2009-983    Completed   1.0000  2009-10-30 00:00:00.000
SFM2045 2009-794    Completed   17.0000 2009-09-24 00:00:00.000
SFM2045 2009-808    Completed   1.0000  2009-09-26 16:01:25.850
SFM2045 2009-811    Completed   3.0000  2009-09-27 09:47:45.543
SFM2045 2009-816    Completed   24.0000 2009-09-30 15:14:35.000
SFM2045 2009-858    Completed   3.0000  2009-10-12 00:00:00.000
SFM2045 2009-861    Completed   .5000   2009-10-13 01:11:50.900
SFM2045 2009-975    Completed   1.0000  2009-10-28 00:00:00.000
SFM2045 2009-984    Completed   3.0000  2009-10-30 00:00:00.000
SFM2088 2009-777    Completed   .5000   2009-10-01 12:49:57.000
SFM2088 2009-853    Completed   .5000   2009-10-09 00:00:00.000
SFM2088 2009-855    Completed   10.0000 2009-10-09 00:00:00.000
SFM2200 2009-753    Completed   8.0000  2009-09-11 00:00:00.000
SFM2200 2009-830    Completed   8.0000  2009-10-09 00:00:00.000

In essence the query needs to:

Return the top 5 assets with the
highest cumulative downtime for the
month of October, and a breakdown of
the associated workorders for these
assets

The query has to be rewritten in such a way that does not require the the existence of Date_Completed criteria in the inner query (is this even possible?). Using Sifu Bill’s answer yielded only 11 rows (there should be 23):

Output from Sifu Bill’s query:

Asset_ID work_order_id status_id downtime_hours Date_Completed

SFM2045 2009-858    Completed   3.0000  2009-10-12 00:00:00.000
SFM2045 2009-861    Completed   .5000   2009-10-13 01:11:50.900
SFM2045 2009-975    Completed   1.0000  2009-10-28 00:00:00.000
SFM2045 2009-984    Completed   3.0000  2009-10-30 00:00:00.000
SFM2200 2009-830    Completed   8.0000  2009-10-09 00:00:00.000
SFM2043 2009-826    Completed   8.0000  2009-10-03 02:00:19.130
SFM2043 2009-983    Completed   1.0000  2009-10-30 00:00:00.000
SFM2088 2009-777    Completed   .5000   2009-10-01 12:49:57.000
SFM2088 2009-853    Completed   .5000   2009-10-09 00:00:00.000
SFM2088 2009-855    Completed   10.0000 2009-10-09 00:00:00.000
SFM2019 2009-828    Completed   8.0000  2009-10-02 00:00:00.000

Thank you for any insight.

  • 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-12T21:48:54+00:00Added an answer on May 12, 2026 at 9:48 pm

    You can try

    SELECT  TOP 100 PERCENT 
            Asset_ID, 
            work_order_id, 
            status_id, 
            downtime_hours 
    FROM    dbo.mtvw_wo_reason1 INNER JOIN
            (
                SELECT  TOP 5 
                        Asset_ID 
                from    mtvw_wo_reason1 
                GROUP   BY Asset_ID, Date_Completed 
                HAVING  Date_Completed BETWEEN '1-Oct-2009' and '31-Oct-2009' 
                ORDER BY    SUM(Downtime_hours) DESC
            ) sub ON dbo.mtvw_wo_reason1.Asset_ID = sub.Asset_ID
    

    EDIT for comment:

    SELECT  TOP 100 PERCENT         
            Asset_ID,         
            work_order_id,         
            status_id,         
            downtime_hours ,
            sub.Date_Completed --added
    FROM    dbo.mtvw_wo_reason1 INNER JOIN        
            (                
                SELECT  TOP 5                                 
                        Asset_ID,
                        Date_Completed --added
                from    mtvw_wo_reason1                 
                GROUP   BY Asset_ID, Date_Completed                 
                HAVING  Date_Completed BETWEEN '1-Oct-2009' and '31-Oct-2009'                 
                ORDER BY SUM(Downtime_hours) DESC        
            ) sub ON dbo.mtvw_wo_reason1.Asset_ID = sub.Asset_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Thanks everbody, things are working 100% now with this query: SELECT e.entry_id FROM
Update Thanks to Marc's help the AlphaPagedList class is now available on CodePlex if
UPDATE : Thanks for all the quick responses. Should have probably clarified that I've
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
Update: Thanks guys, I didn't realize it was very close to zero but not
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
Update: I add a while to get the remain data, problem solved. thanks you
UPDATE: Thanks for all your help guys! I just need to take a litte
Update Thanks to @mrtsherman verifying my code was fine, I dove into the CSS

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.