Question

Asked on 2005-10-26 at 11:20:39ID: 25452273

SQL Query  - Subtraction of two numbers in same field

by: PAH_in_MI500

Rating7.8Very Good

I wrote a query to give me the START and END times, based on the message ID. It works fine, and gives me the two messages associated with start and end.

What I would like to do is subtract the START time displayed from the END time, to give me the actual Runtime and send it to a report that would list LOGDATE and Runtime. No headers are required on the report, simply a file that lists LOGDATE and Runtime

MSGID = 5040 is the start time of a unique process
MSGID = 5041 is the end time of a unique process
Both MSGID's will only appear once daily.

fields in my table:

LOGDATE - CHAR(6)
LOGTIME - CHAR(8)
MSGID - CHAR(4)
$RPT and $DTE assigned variables

Query:

SQL -s << EOF >> $RPT                    
  set pagesize 0                          
  select LOGDATE, LOGTIME                
  from CMR_IOALOG                          
  where (MSGID = '5040' or MSGID = '5041' )
  and LOGDATE = '$DTE'                    
  ORDER by LOGDATE, LOGTIME                
;                                        
EOF        
                             
I haven't a clue where to start. I looked at some of the SUBTRACT questions posted, but almost all talk about subtracting from two different fields in a table. This is from the same field, simply based on the message ID.

Any help is greatly appreciated.

  1. TOP-N SQL statements between two periods.
    I have a number of Database Instances on a number of UNIX Boxes to support. I am looking a SQL Query which can provide me a result of 10 or 20 most time consumed queries ran, say for a period of two months ( For example: between Dec 01/2008 through Feb 01/2009 or say between Jan 01/2009 through Jan 31/2009 that is only f…
  2. SQL STATEMENT WORKS SAME TIME
    Hi, I used the ;with cte as ( select tc1.PK_Field, col.Table_Name, col.Column_Name, col.Data_Type, col.Character_Maximum_Length from INFORMATION_SCHEMA.COLUMNS col INNER JOIN INFORMATION_SCHEMA.TABLES tab on col.Table_Name = tab.Table_Name LEFT JOIN (SELECT ccu.Column_Name as PK_Field, t…
  3. Need a small help in extracting field through PL/…
    I am working on a query in Oracle where I am extracting data from multiple tables. The output will be used in report buidling through XML. There is a field Unit No.: ABC-28-0502 where the first 3 characters (ABC) represent 'Project Name', The next two letter (i.e. 28) represent 'Tower', First two character i.e. '05' represents Floor a…
  4. SQL- how to determine if number is an integer o…
    I have a number coming into my procedure. There are two pieces of logic that need to be run depending on whether the number coming is in an integer or whether it has decimal. How can I determine if it is an integer or not?
  5. update one date field with another, for the same…
    Experts, I have a temporary table filled with history data from the source. Ultimately I need to load it to a real table, but only after I figure something out. I have multiple records per class ( rtclas ), but they are distinct when you factor in effective_date ( which is rtmnth, rtday, and rtyear concatenated ) and rate indicator ( rtrind ). There can be …

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
subtraction sql
Participating Experts
2
Solution Grade
A

Replies

 by: ram_0218

Posted on 2005-10-26 at 11:31:01ID: 28197129

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: DrSQL

Posted on 2005-10-26 at 11:35:26ID: 28197130

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ram_0218

Posted on 2005-10-26 at 11:36:38ID: 28197131

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 11:43:13ID: 28197132

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ram_0218

Posted on 2005-10-26 at 11:44:24ID: 28197133

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 11:44:40ID: 28197134

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: ram_0218

Posted on 2005-10-26 at 11:48:55ID: 28197135

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 11:52:08ID: 28197136

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 11:53:07ID: 28197137

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: DrSQL

Posted on 2005-10-26 at 11:53:29ID: 28197138

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 11:55:23ID: 28197139

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: DrSQL

Posted on 2005-10-26 at 12:05:02ID: 28197140

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 12:16:40ID: 28197141

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: DrSQL

Posted on 2005-10-26 at 12:25:25ID: 28197142

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: DrSQL

Posted on 2005-10-26 at 12:29:26ID: 28197143

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 12:37:29ID: 28197144

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by:

Posted on 2005-10-26 at 12:40:09ID: 28197145

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 12:40:49ID: 28197146

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: PAH_in_MI

Posted on 2005-10-26 at 12:43:10ID: 28197147

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert