Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with SQL-statement !
The keywords are sum(), case when ... then ... else ... end, and group by.
Rene
> Hi everybody !
>
> I am an SQL-Newbie, who could need some help.
>
> I have a table, "Stocktrans", with the following fields:
>
> DATE QTY
> ---------- ------
> 01-01-2000 20
> 01-01-2000 4
> 01-01-2000 -5
> 01-01-2000 -2
> 10-02-2000 -3
> 20-03-2000 3
> 20-03-2000 -1
> 20-03-2000 -4
>
> QTY>0 means inflow to my stock, and QTY<0 means OUTFLOW of my stock. I
> now want to make a script with 4 columns.
>
> Column 1: Date
> Column 2: Sum of stock INFLOW on that date
> Column 3: Sum of stock OUTFLOW on that date
> Column 4: Stocklevel at the end of the day.
>
>
> The output should look like this:
>
> DATE INFLOW OUTFLOW STOCKLEVEL
> ---------- ------ ------- ----------
> 01-01-2000 24 7 17
> 10-02-2000 3 14
> 20-03-2000 3 5 12
>
> Hopefully someone can help me.
>
> Regards,
> Ole
-- Rene Nyffenegger http://www.adp-gmbh.ch/Received on Mon Mar 14 2005 - 13:10:36 CST