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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:49:45+00:00 2026-05-12T00:49:45+00:00

I’ve written an SQL query that produces a report of some stats for each

  • 0

I’ve written an SQL query that produces a report of some stats for each Year-Week-Mine-Product.

It works exactly as desired except for one thing – trn.wid-date isn’t the correct date to be using.

I should be using td.datetime-act-comp-dump. When I replace trn.wid-date with td.datetime-act-comp-dump, it doesn’t give me any errors but seems to just hang indefinitely. I let it go for a while yesterday and it came back with ORA-01652 unable to extend temp segment by 128 in tablespace TEMP, though I haven’t seen that error since.

I don’t understand what might be causing that considering that I’m able to successfully return MAX(td.datetime-act-comp-dump) in the query below

select to_char(trn.wid_date, 'IYYY') as dump_year,
       to_char(trn.wid_date-7/24, 'IW') as dump_week,
       SUBSTR(trn.train_control_id,1,2) as Mine,
       vcon.product_type_code as Product,
       COUNT(DISTINCT trn.train_control_id) as Trains,
       COUNT(1) as Wagons,
       MIN(trn.wid_date) as Min_WID_Hrs,
       MAX(trn.wid_date) as Max_WID_Hrs,
       MIN(td.datetime_act_comp_dump) as Min_Fin_Dump,
       MAX(td.datetime_act_comp_dump) as Max_Fin_Dump,        
       ROUND(SUM(con.weight_total-con.empty_weight_total),0) as Tot_Tonnes,       
       ROUND(AVG(con.weight_total-con.empty_weight_total),2) as Avg_Tonnes,
       ROUND(MIN(con.weight_total-con.empty_weight_total),2) as Minimum,
       ROUND(PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY (con.weight_total-con.empty_weight_total) DESC),2) as "1st",      

from  widsys.consist con
      INNER JOIN widsys.train trn
      USING (train_record_id)
      INNER JOIN tpps.train_details td
      ON trn.train_tpps_id||trn.mine_code = td.train_id||td.mine_code
      INNER JOIN widsys.v_consist_ore_detail vcon
      USING (consist_id)

where trn.direction = 'N'
      and to_char(trn.wid_date, 'IYYY') = 2009
      and to_char(trn.wid_date-7/24, 'IW') = 25

group by to_char(trn.wid_date, 'IYYY'),
         to_char(trn.wid_date-7/24, 'IW'),
         SUBSTR(trn.train_control_id,1,2),
         vcon.product_type_code

order by to_char(trn.wid_date-7/24, 'IW') DESC

Just in order to troubleshoot, from the query above, I’ve tried removing everything to do with vcon and replacing trn.wid_date with td.datetime-act-comp-dump. The effect is that it only reports on Year-Week-Mine rather than Year-Week-Mine-Product. (see query below)

This new query actually executes rather than just hanging, but returns a few odd results and doesn’t isn’t sufficient since it doesn’t break things down on Product.

select to_char(td.datetime_act_comp_dump, 'IYYY') as dump_year,
       to_char(td.datetime_act_comp_dump-7/24, 'IW') as dump_week,
       SUBSTR(trn.train_control_id,1,2) as Mine,
       --vcon.product_type_code as Product,
       COUNT(DISTINCT trn.train_control_id) as Trains,
       COUNT(1) as Wagons,
       MIN(trn.wid_date) as Min_WID_Hrs,
       MAX(trn.wid_date) as Max_WID_Hrs,
       MIN(td.datetime_act_comp_dump) as Min_Fin_Dump,
       MAX(td.datetime_act_comp_dump) as Max_Fin_Dump,        
       ROUND(SUM(con.weight_total-con.empty_weight_total),0) as Tot_Tonnes,       
       ROUND(AVG(con.weight_total-con.empty_weight_total),2) as Avg_Tonnes,
       ROUND(MIN(con.weight_total-con.empty_weight_total),2) as Minimum,
       ROUND(PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY (con.weight_total-con.empty_weight_total) DESC),2) as "1st"       

from  widsys.consist con
      INNER JOIN widsys.train trn
      USING (train_record_id)
      INNER JOIN tpps.train_details td
      ON trn.train_tpps_id||trn.mine_code = td.train_id||td.mine_code
      --INNER JOIN widsys.v_consist_ore_detail vcon
      --USING (consist_id)

where trn.direction = 'N'
      and to_char(td.datetime_act_comp_dump, 'IYYY') = 2009
      and to_char(td.datetime_act_comp_dump-7/24, 'IW') = 25

group by to_char(td.datetime_act_comp_dump, 'IYYY'),
         to_char(td.datetime_act_comp_dump-7/24, 'IW'),
         SUBSTR(trn.train_control_id,1,2)
         --vcon.product_type_code

order by to_char(td.datetime_act_comp_dump-7/24, 'IW') DESC

Any advice on what might be going wrong?

Cheers,

Tommy

  • 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-12T00:49:45+00:00Added an answer on May 12, 2026 at 12:49 am

    I managed to get it to run muuuuuuuch faster by creating a subquery for widsys tables and one for tpps tables. Then doing an implicit inner join on two columns instead of concatenating.

    SELECT blah FROM (widsys subquery) w, (tpps subquery) t WHERE w.mine_code = t.mine_code and w.train_id = t.train_tpps_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.