SQL & PL/SQL :: Value Of First And Last Sale

Aug 29, 2013

I have a sales table where i need to get same indicators about the account, I get the date of first sale and the date of last sale, but I need to get the value of first sale (min date) and the last sale (max date)

WITH My_table AS
(
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130801', 'YYYYMMDD') DTCREATED, 1000 as Value FROM dual UNION ALL
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130815', 'YYYYMMDD') DTCREATED, 400 as Value FROM dual UNION ALL
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130807', 'YYYYMMDD') DTCREATED, 2600 as Value FROM dual UNION ALL
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130808', 'YYYYMMDD') DTCREATED, 500 as Value FROM dual UNION ALL
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130811', 'YYYYMMDD') DTCREATED, 450 as Value FROM dual UNION ALL
SELECT '0001' ID_ACC, 'ABC' Cod_Product, to_date('20130802', 'YYYYMMDD') DTCREATED, 4000 as Value FROM dual UNION ALL

[Code]....

Where i will get

ID_ACC = 0001
CPD_PRODUCT = ABC
DATE_START = 20130801
DATE_LAST = 20130828
NUM_DAYS = 27
NUM_SALES = 10

And i need this two values

VALUE_FIRST = 1000 (on 20130801)
VALUE_LAST = 10 (on 20130828)

How can i get VALUE_FIRST and VALUE_LAST without using temp tables or sub-select ?

View 2 Replies


ADVERTISEMENT

PL/SQL :: How To Get Max Total Sale By Date On Every Store

Jul 6, 2013

I am trying to write a query in Oracle which will return both the store_id and the maximum total sale by date

View 3 Replies View Related

Forms :: Inventory Sale Program In Oracle

Apr 15, 2010

I have made the inventory sale program in oracle. Its working from 7 years. Now its speed is very slow.It take much time to execute query.

View 17 Replies View Related

SQL & PL/SQL :: Report Deign To Generate Month Wise Sale - Date Format

Sep 23, 2013

how to write pl/sql to create date o/p like .

since we wnat to design pl/sql report wich will generate monthwise sale from 01jan2009 to 01-sep-2013.

we have created funtion wich will accept argument as employee no, from date and to date.

from_date to_date
01-JAN-2009 01-FEB-2009
01-FEB-2009 01-MAR-2009
01-MAR-2009 01-APR-2009
01-APR-2009 01-MAY-2009
01-may-2009 01-JUN-2009
01-JUN-2009 01-JUL-2009

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved