Question

SQL Query  - Subtraction of two numbers in same field

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. How do I concaternate two 4000 character v…
    Hi, I need to feed several varchar entries into one CLOB field. Straight concaternation doesn't work. Each varchar is araound 4000 characters in length. I need this to be done within SQl. Cheers.
  2. SQL query help - including a field from a second…
    I have a simple query that gets all the data from the table 'SUMMARY' and two fields from the table 'SIGNED': select R.*, A.SIGNED, A.ARCHIVED from SUMMARY R left join SIGNED A on R.SET_ID = A.SET_ID I am really struggling with bringing in an extra field REPLYDATA.REPLYTEXT whereby I want to bring in the very latest …
  3. sql query required get the number between two …
    hello-10000234-test i want number between two - hiphens i.ee 1000234 how can i get this
  4. 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, tc…
  5. 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 fo…

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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:

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

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

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