Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Dell PowerEdge Servers
  #1  
Old April 12th, 2003, 12:32 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Oracle Need simple totals for day and by week

How do I do a query that'll give a sum of something by day for a week?

Output for would need to be...

Code:

                Quantity On Hand

          04/01/03  04/02/03 04/03/03  TOTAL
PartA      5         10         25     40
PartB      1          5          5      11
   
GrandTL    6          15        30     51


Last edited by vrkelley : April 12th, 2003 at 12:41 PM.

Reply With Quote
  #2  
Old April 12th, 2003, 02:47 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,733 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 20 h 11 m 38 sec
Reputation Power: 869
you'll need something that can produce "crosstab" output -- some report writer or reporting utility -- because doing it in sql is really difficult

it's easy to produce daily and weekly sums, and even both in the same query, but not to arrange daily sums across the line like that, with weekly totals on the right

oracle has a paramater for one of its date functions that extracts the ISO week number for any date

see Grouping output by week

in your case you'd want to GROUP BY the daily date as well as the week number, and let the reporting program do its crosstabbing by week

rudy
http://r937.com/

Reply With Quote
  #3  
Old April 12th, 2003, 03:34 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
>you'll need something that can produce "crosstab" output

GAHK!
The data has no history stuff of what the inventory looked like last week etc...only what's on the shelves with cur date_time!

...do I have to search the backups for each day to get this?

If so...how do I define an accumulator would be needed for:
Each day
Grand Total

Is a schema change needed?

-V
PS Our new DBA from Toronto just handles backups. We engineers are stuck with the rest...

Reply With Quote
  #4  
Old April 12th, 2003, 03:36 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Err
Perhaps I could create a secondary table that stores totals at the end of each night? Then do the query from that?

If so can Oracle do a time-based stored proc?

thanks Rudy
-V

Last edited by vrkelley : April 12th, 2003 at 03:39 PM.

Reply With Quote
  #5  
Old April 12th, 2003, 04:12 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,733 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 20 h 11 m 38 sec
Reputation Power: 869
can't really help you, V, without more details

you want a "sum of something" but have no history more than a week old?

you may need an accumulator, or secondary table, but the design will depend on so many factors, you should look into all your options before thinking about how to make the output look pretty

("look pretty" is not an epithet, report design cannot be overlooked, but having a good data architecture is of primary importance)

please give a brief description of the table(s), how they are updated, and how often

rudy

Reply With Quote
  #6  
Old April 12th, 2003, 04:18 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 20 h 2 sec
Reputation Power: 19
You can do it with a decode.

ie select sum(decode(dayofweek,'monday',onhand,0) monday, sum(decode(dayofweek,'tuesday',onhand,0)...

Give me your table structure if you need more help.

Reply With Quote
  #7  
Old April 12th, 2003, 09:12 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
The data shows only where the parts are this second.
Each time a part moves, one of the quanities increments or decrements. Schema looks something like this

part_number (varchar2)
component _key (number)--> foreign key describing category. Ex. Fan, Bracket
qty_reserved(number) ----> while their filling the order
qty_available(number)-----> sitting on shelf
qty_in_chassis(number) ---> sitting in chassy waiting to be boxed
description etc
stuff
stuff



-V

Last edited by vrkelley : April 12th, 2003 at 09:46 PM.

Reply With Quote
  #8  
Old April 12th, 2003, 10:26 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
>you want a "sum of something" but have no history more than a week old?

I'll tell mgt that it's not possible. But we'll need to start storing the data some how.

So at the end of the day some how the counts for each product will have to get stored to another table. Is there a way to automatically launch a stored procedure to do that ?

-V

Reply With Quote
  #9  
Old April 12th, 2003, 10:59 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,733 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 20 h 11 m 38 sec
Reputation Power: 869
yes, regular copying of the data into another table is a great idea -- add a timestamp column

go to whoever set the database up or is currently responsible for it, somebody called "database administrator" preferably, and ask them to set it up for you

oracle has utilities for this

good luck

Reply With Quote
  #10  
Old April 13th, 2003, 11:19 AM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
hmm....Our "DBA's" only do reboots, back ups and install patches and also would NOT give the Oracle utilities.

Need to insert 1 row of data for each part each day into the table that'll hold the inventory history stuff.

A. Is there a command line way to *schedule* this sort replication ?

B. In the stored proc, do I have to define a variable for each item extracted on the old table? Something like this prob won't work because it returns too many values?

Code:
INSERT  INTO tblHistory 
      VALUES(SELECT x, y, z SUM(z)), sysdate  /*x, y, z  data format to match new table's schema */
FROM tblpartinfo) 

Reply With Quote
  #11  
Old April 13th, 2003, 01:01 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,401 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 h 24 m 39 sec
Reputation Power: 255
Quote:
A. Is there a command line way to *schedule* this sort replication ?


Check http://www.databasejournal.com/feat...cle.php/1563801

Reply With Quote
  #12  
Old April 13th, 2003, 06:32 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 20 h 2 sec
Reputation Power: 19
You could use dbms_job to do the move. It is kind of like a cron capability within oracle. It is usually installed by default.

Reply With Quote
  #13  
Old April 13th, 2003, 09:40 PM
vrkelley vrkelley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 38 vrkelley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Wow ultra...that looks like it'll work. I'm thinkng the schema of the history table will look like this...but...

Part_skey
Part#
Qty On Hand(sum of next three columns reflect daily TL
Qty in Chassy
Qty in Reserve
Lastupdate


I don't understand how to get each week's rpt to show the new range of dates in the heading?
--------------------------------------------------------------------------------
Code:
                Quantity On Hand

          04/01/03  04/02/03 04/03/03  TOTAL
PartA      5         10         25     40
PartB      1          5          5      11
   
GrandTL    6          15        30     51




Last edited by vrkelley : April 13th, 2003 at 09:54 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Oracle Need simple totals for day and by week


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump