Query help, subtract two query parts

Hi,
I am beginner of PL/SQL and have a problem I couldn’t solve:
Table (op_list):
Item     -     Amount -     Status
Item1     -     10     -     in
Item2     -     12     -     in
Item3     -     7     -     in
Item1     -     2     -     out
Item2     -     3     -     out
Item1     -     1     -     dmg
Item3     -     3     -     out
Item1     -     2     -     out
Item2     -     5     -     out
Item2     -     2     -     in
Item3     -     1     -     exp
Would like to get result of query (subtract amount of 'out/dmg/exp' from 'in' ):
Item - Amount left
Item1     -     5
Item2     -     6
Item3 -     3
I wrote code that returns sum of all incoming items and sum all out/dmg/exp items, but couldn’t solve how to subtract one part of querry from another. Or maybe there is a better way. Also worried what happens if there is no 'out/dmg/exp' only 'in'
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'in'
group by item.name
union
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'out'
or op_list.status = 'dmg'
or op_list.status = 'exp'
group by item.name
Return:
Item1     -     10      [10 in]
Item1     -     5     [2+1+2]
Item2     -     14     [12+2]
Item3     -     7
Item3     -     4     [3+1]
Thanks in advance

Hi,
We can also use simple inline views to get what we need.
select a.item,a.amount-b.amount Balance from
(select item,sum(amount) Amount from op_list
where status = 'in'
group by item) a,
(select item,sum(amount) Amount from op_list
where status in ('out','dmg','exp')
group by item) b
where
a.item=b.item
order by item;
ITEM       BALANCE
Item1                      5
Item2                      6
Item3                      3Regards,
Prazy

Similar Messages

  • Subtract two characters in a query

    Hi Experts,
    I want to know how to subtract two characters in a query could you please give me the solution regarding this.
    Ex: posting date - Document date
    Regards,
    Krish

    Hi,
    this can be achieved by creating two formula variables for 2 chars with replacement path and do a subtraction.
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    Assign points if this is helpful...........
    Rgs,
    I.R.K

  • How to display two different parts of one image in two windows?

    hi everyone:) i need to display two different parts of one image in two windows. i have problem with displaying :/ because after creating windows there aren't any images :( i supose my initialization code of creating windows is incomplete, maybe i miss something or maybe there is some inconistency. graphics in java is not my strong position. complete code is below. can anybody help me?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    import java.util.*;
    class ImgFrame extends JFrame
           private BufferedImage img;
           ImgFrame(BufferedImage B_Img, int x, int y, int w, int h)
                   super("d");
                   img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
                   img=B_Img.getSubimage(x, y, w, h);
           }//end ImgFrame construction
           public void paint(Graphics g)
                   Graphics2D g2D = (Graphics2D)g;
                   g.drawImage(img, 8, 8, null);
           }//end paint method
           public Dimension getPrefferedSize()
                   if(img==null)
                           return(new Dimension(100,100));
                   else
                           return(new Dimension(img.getWidth(null),img.getHeight(null)));
           }//end of GetPrefferedSize method
    }//end ImgFrame class
    public class TestGraph2D_03 extends Component
           static BufferedImage IMG;
           public static void Load()
                   try
                           IMG=ImageIO.read(new File("c:/test.bmp"));
                   catch(IOException ioe)
                           System.out.println("an exception: "+ioe);
                   }//end try catch
           }//end TestGraph2D_03 construction
           public static void main(String[] args)
                   Load();
                   ImgFrame F1 = new ImgFrame(IMG, 0, 0, 8, 8);
                   ImgFrame F2 = new ImgFrame(IMG, 8, 8, 8, 8);
                   F1.addWindowListener(new WindowAdapter()
                           public void windowClosing(WindowEvent e)
                                   System.exit(0);
                   F1.pack();
                   F1.setVisible(true);
                   F2.addWindowListener(new WindowAdapter()
                           public void windowClosing(WindowEvent e)
                                   System.exit(0);
                   F2.pack();
                   F2.setVisible(true);
           }//end of main method in TestGraph2D_01 class
    }//end of TestGraph2D_03 class

    Never override the paint(...) method of a Swing component.
    If you have a sub image then add the image to a JLabel and add the label to the GUI. No need for custom painting.

  • Overlapping the two web part ??

    Hi,
    i am having the overlapping issue with two web part zone in SP 2013 like the following screen shot in my custom page layout. how can i resolve this issue?
    Thanks

    Hi Rahul,
    Thanks for your reply. Actually i am creating a table with row and columns in Custom page layout. in my table there will be few rows with columns. if i use following html and overlapping web part each other. As i want to have more than 2 web part will be
    in one row with separated columns. Please correct me if i need to change the html.
    <table>
    <tr>
    <td>
    getting web part zone from snippet
    </td>
    <td>
    getting web part zone from snippet
    </td>
    </tr>
    <tr>
    <td>
    getting web part zone from snippet
    </td>
    </tr>
    </table>

  • All of a sudden my login password won't be accepted can any one help but the weird part is after a few min the computer just turns its self on

    All of a sudden my login password won't be accepted can any one help but the weird part is after a few min the computer just turns its self on

    This happened to me, too. I couldn't log in to ANY accounts on the machine. Restarted, failure again, restarted again.
    Solution:  Wait.
    After restarting I let the machine sit for a minute. Then it worked!
    I ran Onyx and repaired permissions. Big mistake, apparently. Now  I have to type my admin password everytime I want to move or save. All my Office docs open as Read-Only.

  • Help with two scripts - Mounting remote DMG and Checking which network I'm connected to

    Hey guys, I need some help with two separate scripts:
    1. The first script I'm trying to create to mount a DMG stored remotely on another Mac using an AppleScript or shell script. Using the following:
    set cmd to "hdiutil mount 'afp://username:[email protected]/Lion/Users/username/Desktop/Test.sparseim age'"
    do shell script cmd
    results in the following error:
    error "hdiutil: mount failed - not recognized" number 1
    I'm not very experienced regarding AppleScript or using hdiutil, could somebody point out what's wrong with my script?
    2. The second script I'm working on to try and essentially prevent the 'Could Not Find Server' Finder dialog when a network mount is unavailable. I guess what I'd like it to do is detect which network I'm connected to, and if I'm connected to the correct network, then mount the shares, otherwise just fail silently without any errors. From the searching I've done, using try statements should do this, but they do not, and I'm still presented with an error dialog after the server cannot be found.
    Does anybody have any suggestions on this script? Also, I've seen some tips regarding detecting which wireless network the Mac is connected to, which could work, but what about when connected via Ethernet?
    Thanks!

    Edit: I need to clarify on my first script request:
    I need to mount the DMG on the remote Mac, not on the Mac I'm running the script from.

  • F4 HELP ON TWO DIFFERENT FIELDS OF A SCREEN .

    Hi Experts ,
    I have a screen  in which i have to aply f4 help on two different fields .
    1. Bussiness unit
    2. SAP GL Account .
    I  have applied for  Bussiness unit. by :
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1013.
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_1013.
       PROCESS ON VALUE-REQUEST.
    field B_UNIT MODULE SEARCHHELP_F4.
    But how i can apply on SAP GL Account  ,i have to use one more POV module or i can do it by using the same pov which i used for Bussiness unit.
    Please tell me how i can do with little bit code example.
    Regards,
    Premraj

    Hi,
    use one more FIELD statement and create one more module for GL a/c in same POV event.
    ex
    FIELD <GL a/c fld name> MODULE <Module name>.

  • Subtract   two dates to get   months and days

    I havew to subtract two dates and get the differnce ,
              Date issuedDate= myobj.getIssueDate();
              Date expirationDate=DateUtils.addMonths(issuedDate, 6);
              long timeDiff=expirationDate.getTime()-new Date().getTime();
              long daysRemaning=timeDiff/86400000;this is code I get the number of days between the issue date and todays date.now my client wants not just days but months and days , i need suggestions on how to get days and months between any two given dates

    I have read that it is best to use java.util.Calendar for almost any time related issue.
    With some switch statements and a for loop, I think the Calendar class could solve the problem.

  • Query help first two rows

    i need to sort desc order by date and need to take two rows only
    id date
    1 1/2/1994
    2 2/2/2000
    3 1/5/88
    4 6/5/2006
    i need out put like this
    id date
    4 6/5/2006
    2 2/2/2000
    plz give query with good perfomence thanks

    You can use any one of the below query which performs better for you
    SQL> with t
      2  as
      3  (
      4  select 1 id,to_date('1/2/1994','dd/mm/yyyy') dt from dual
      5  union all
      6  select 2,to_date('2/2/2000','dd/mm/yyyy') from dual
      7  union all
      8  select 3,to_date('1/5/88','dd/mm/yyyy') from dual
      9  union all
    10  select 4,to_date('6/5/2006','dd/mm/yyyy') from dual
    11  )
    12  select * from
    13  (
    14  select * from t
    15  order by 2 desc
    16  )
    17  where rownum <=2
    18  /
            ID DT
             4 06-MAY-06
             2 02-FEB-00
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=2 Bytes=24)
       1    0   COUNT (STOPKEY)
       2    1     VIEW (Cost=9 Card=4 Bytes=48)
       3    2       SORT (ORDER BY STOPKEY) (Cost=9 Card=4 Bytes=48)
       4    3         VIEW (Cost=8 Card=4 Bytes=48)
       5    4           UNION-ALL
       6    5             FAST DUAL (Cost=2 Card=1)
       7    5             FAST DUAL (Cost=2 Card=1)
       8    5             FAST DUAL (Cost=2 Card=1)
       9    5             FAST DUAL (Cost=2 Card=1)
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            416  bytes sent via SQL*Net to client
            496  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              2  rows processed
    SQL> with t
      2  as
      3  (
      4  select 1 id,to_date('1/2/1994','dd/mm/yyyy') dt from dual
      5  union all
      6  select 2,to_date('2/2/2000','dd/mm/yyyy') from dual
      7  union all
      8  select 3,to_date('1/5/88','dd/mm/yyyy') from dual
      9  union all
    10  select 4,to_date('6/5/2006','dd/mm/yyyy') from dual
    11  )
    12  select id,dt
    13  from
    14  (
    15  select id,dt,row_number() over(order by dt desc) rn from t
    16  order by 2 desc
    17  )
    18  where rn <=2
    19  /
            ID DT
             4 06-MAY-06
             2 02-FEB-00
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=4 Bytes=100
       1    0   VIEW (Cost=8 Card=4 Bytes=100)
       2    1     WINDOW (SORT PUSHED RANK) (Cost=8 Card=4 Bytes=48)
       3    2       VIEW (Cost=8 Card=4 Bytes=48)
       4    3         UNION-ALL
       5    4           FAST DUAL (Cost=2 Card=1)
       6    4           FAST DUAL (Cost=2 Card=1)
       7    4           FAST DUAL (Cost=2 Card=1)
       8    4           FAST DUAL (Cost=2 Card=1)
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            416  bytes sent via SQL*Net to client
            496  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              2  rows processed

  • Help Merging And Deleting Part Of Two Images

    Hi All,
    im having trouble with cutting part of a image out and putting it ontop of another to form one image i used to use gimp before but ive started using photoshop after building my own PC
    these are the two images i want merging:
    https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTfNmYfTBCmaN3zTV3_qrrQF48rJPd3QUrW5E t3AiDe-x8RD5rX
    https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRYeijxO3WUIMajNSW_RMvb5u0ksNGrgHGMCG 5Pc7ZqY25ABnNtKg
    its for a tattoo design no doubt most wont like it but hey ho, i want the woman in the middle of the second picture placing inbetween the two faces one the first image (if you understand what i mean) im not to bothered about all the writing as i will be having a saying underneath it all
    any suggestions on the best way to go about this need the image to look as clear as possible and 6" high and 10 wide
    thanks

    Hi EvilJester2013,
    It sounds like you want to composite two images together, this very helpful tutorial can help you with that: http://www.smashingmagazine.com/2010/12/16/compositing-in-adobe-photoshop-time-saving-tips /

  • I need help dividing an image into two equal parts in Adobe Illustrator CC--ASAP!!!

    I need help dividing a single, already created image into 2 equal parts...Am getting nowhere so far

    Hi Willi, thanks so much for responding! Below is the image I need to divide in half. The left half where it says "Click here for the definition" links to a landing page where people can read the definition of the Hebrew Word. The right half links to an audio recording of the Hebrew word being spoken aloud. I am trying to figure out how to use the scissors or knife tool in Adobe Illustrator and am having no luck. Plus I believe there's a way to include URLs on each separated part, but I can't get past figuring out how to cut it. My background is not graphic design

  • Need Help Identifying Two HP ZD7000 Parts

    Hi,
    The DC power jack on my Pavilion ZD7000 went bad, a common problem. I had never taken a laptop computer apart before but decided I would give it a try and replace the jack myself. If I failed in my effort, no great loss since the computer is an old one.
    I carefully followed steps from several online sources and noted and catalogued every screw, etc.
    However, I didn't account for the fact that loose parts would fall from the computer when I turned it over. The two parts in question are in the image below. I have not been able to determine where they go. If you have any thoughts or insights, please let me know. I have no idea how critical they are to the computer's operation.
    Thanks,
    Bill

    I looked at the service manual, too. There is nothing depicted which looks anything like these two things. HP Service Manuals have improved a lot since this thing was created; very sketchy and bare bones. I am going to go out on a limb and say the flat shiny thing is a bracket for something like the optical drive, or it maybe holds the video cable in place after it has been plugged into the motherboard. The other thing looks like a button to eject something like from the card reader. I would say neither is critical to the functioning of the system, but the absence of the spring-loaded thing will likely mean if you put a card or whatever in the slot it may be hard to get it out.

  • Chapter marker help and two-part DVD's

    Hi,
    I've got a dance show that I have edited and now need to put into a DVD. I have a couple of questions I need answering so would really appreciate a little help
    The show is in two halves - first half and second half (duh lol). Do I need to put each half into a separate sequence and then open in Encore, or do I just have it as one long sequence?
    I've figured out there are Encore Chapter Markers, which I've set accordingly - is there anything different I need to do when it comes to two halves?
    Thanks for your help!
    Nath

    Hi Nath,
    AME = Adobe Media Encoder. From Premiere, make sure your Sequence is selected, then use File > Export > Media and this launches AME. Maybe I'm old school, but I prefer the control I have using AME directly versus Dynamic Link which is more "auto pilot". I think what I like is that if I encode my Sequence to "MPEG-2 for DVD" prior to opening Encore, then Encore doesn't have to encode the video, which means once my menus are done, I can have a proof DVD in hand in literally minutes! I'm usually ready for a break when completing an edit, so then is a good time for me to encode, then I come at the DVD authoring fresh and have no wait for encoding in that process.
    The only catch with manually encoding the DVD content is to get the correct encoding rate so it all fits the disc. I use the formula 560/minutes=rate, so for instance 560/120=4.66 and I just round down a bit to 4.5 to allow for any overhead.
    In AME, choose "MPEG-2 for DVD" for format and for the preset, choose what is appropriate to your footage, for instance "NTSC Widescreen High Quality". Then under the VIDEO tab, you can choose CBR or VBR (Constant or Variable Bit Rate) and set the bit rate according to program length. Google CBR and VBR because I know that will be the next question. I prefer CBR unless program is very long.
    This will Export TWO files - an .m2v for video, and .wav for audio. Any chapter marks in Premiere are written to other files, but you need not worry about those. In Encore, start a new DVD project, then use File > Import > As Timeline and just multi-select both the .m2v and .wav files. They will import to a timeline, with chapter marks included!
    When you finally build the project, the .wav audio is by default converted to Dolby Digital, which is much smaller than .wav, so if you are adding the sizes of the .m2v and .wav and think "they won't fit the disc", the audio compression should fix that if you encoded at the correct rate.
    As mentioned, the nice thing is that when you Build, you will see the progress bar Transcoding Audio, but not video, so it goes VERY quickly, just a couple of minutes to build a 2-hour DVD unless you have complex motion menus to render.
    Hope I'm not adding more confusion, go ahead and use Dynamic Link if that is most comfortable for you, but good to know how to use AME as well.
    Thanks
    Jeff Pulera
    Safe Harbor Computers

  • Select Query: Part of the field

    Hello Experts,
    I have an issue.
    In my selection from one table T1, i need to select just lines that have the field F1 begins by some numbers. For example, all lines that have the field F1 like that '12345678xxxxx'. 
    The problem is: in my selection i can't use 'Like %' or a range with Option 'CP'  because the field F1 is a DECIMAL and not a CHAR!!
    In the fact, the field is in the format: 'AAAAMMJJhhmmss', and i want  all lines that have the date 'AAAAMMJJ'  irrespective of the hour.  The type of this field is DECIMAL 15.
    Do you have any idea how i can do it?
    Thank you in advance.

    Could you try to get all data say between 20081211000000 and 20081211235959 ?
    This may work to solve your problem.

  • Subtracting two numbers in double format gives incorrect result

    Hello,
    I have a table with two fields in Number (Field Size: Double; Decimal Places: Auto).  When using a query i try to subtract one field from the other I get incorrect results:
    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
    3.98002225218796E-04
    0.644498511499839
    0.645908903902985
    -1.41039240314556E-03
    1.51021791504783
    1.51372591514976
    -3.50800010193808E-03
    <tfoot></tfoot>
    When I paste the above into Excel, I get the correct results:
    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
                         0.00039800222521880
    0.64449851149984
    0.64590890390299
                       (0.00141039240314556)
    1.51021791504783
    1.51372591514976
                       (0.00350800010193808)
    Would much appriciate any help in how to get the correct values in Access Query.
    Thank you

    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
    3.98002225218796E-04
    0.644498511499839
    0.645908903902985
    -1.41039240314556E-03
    1.51021791504783
    1.51372591514976
    -3.50800010193808E-03
    Hi Vasilii,
    In my opinion the results are correct, only they are presented in scientific notation. You can do some formatting, to display the results the way you want.
    See the Help on the use of Format.
    Imb.

Maybe you are looking for

  • Frequent "Invalid URL" problem on my MacBook

    I have a strange problem accessing websites with my MacBook. I'll go to a website like Google, Amazon, Netflix, etc, and intermittently, I'll get the following error message: Invalid URL The requested URL "http://www.netflix.com/", is invalid. Refere

  • I am trying to connect an IPOD NANO 7 GEN to an IPOD dock that has a 30pin slot.

    I have an ipod nano 7 gen that i would likee to connect to my Panasonic audio system. They supply a dock with a 30 pin socket. What do i need to connect the two?

  • Color Finesse for Premiere CS6

    Enjoying Color Finesse in AE but would like to use the Premiere version.  I have downloaded the program from the website but it requires a serial number to active in Premiere.  It is my understanding that this serial number comes with my purchase of

  • Save output text in automator

    So I've got automator to output selected files from the system profiler, and then into a text document.  Now, I want automator to save this text docuemnt. Searching the Library of actions in Automator for SAVE give me 2 choices and none of them do wh

  • Anything similar to Smart Objects for bitmap images in Fw?

    In Ps you're able to place a bitmap image on a layer and convert it to a Smart Object, allowing you to resize that image non-destructively. Is there a way to achieve this in Fw?