- SQL> ED
-
Wrote file afiedt.buf
-
-
1 select ROUND(avgprice, 10) avgprice, SeQ_no
-
2 from (select b.*,
-
3 sum(decode(INVXH_code, 'BUY', invxh_TOTAL_QTY, -invxh_TOTAL_QTY)) OVER (ORDER BY INVXH_date) BALQTY,
-
4 row_number() over (order by invxh_DATE) seq_no
-
5 from INVS_TXN_HEAD b)
-
6 -- where INVXH_BROK_code = :INVXH_BROK_code
-
7 -- AND INVXH_Securit_CODE = :INVXH_Securit_CODE
-
8 where INVXH_date < to_DATE('25/02/2008','dd/mm/yyyy')
-
9 model
-
10 dimension by (seq_no)
-
11 measures (invxh_DATE
-
12 , INVXH_code
-
13 , INVXH_no
-
14 , invxh_TOTAL_qty
-
15 , balqty
-
16 , INVXH_net_AMOUNT_scy netAMT
-
17 , 0 balamt
-
18 , 0 balamt2
-
19 , 0 avgprice
-
20 , 0 cost)
-
21 rules (
-
22 balamt[seq_no is any] = nvl(balamt[cv() - 1], 0) +
-
23 decode(INVXH_code[cv()], 'BUY', netamt[cv()] , -(balamt[cv() -1] /
-
24 balqty[cv() -1] * invxh_TOTAL_qty[cv()]) ) ,
-
25 cost[seq_no is any] = decode(INVXH_code[cv()], 'SEL', balamt[cv() -1] /
-
26 balqty[cv() -1] * invxh_TOTAL_qty[cv()], 0),
-
27 avgprice[seq_no is any] = decode(INVXH_code[cv()], 'BUY', balamt[cv()] /
-
28 balqty[cv()] , avgprice[cv() - 1])
-
29* )
-
SQL> /
-
-
AVGPRICE SEQ_NO
-
-------------------- -------------
-
2.22124210670000 1.000
-
2.24828175450000 2.000
-
2.22339370630000 3.000
-
2.19552193330000 4.000
-
2.17612187560000 5.000
-
-
SQL>
where should i modify the query to get just the last row no. 5
i tried to change with line no.9 ,,but got just seq_no col. and that also, with the value 6;
i want the query to return " 2.17612187560000 5.000" - SQL> ed
-
Wrote file afiedt.buf
-
-
1 select ROUND(avgprice, 10) avgprice, SeQ_no
-
2 from (select b.*,
-
3 sum(decode(INVXH_code, 'BUY', invxh_TOTAL_QTY, -invxh_TOTAL_QTY)) OVER (ORDER BY INVXH_date) BALQTY,
-
4 row_number() over (order by invxh_DATE) seq_no
-
5 from INVS_TXN_HEAD b)
-
6 -- where INVXH_BROK_code = :INVXH_BROK_code
-
7 -- AND INVXH_Securit_CODE = :INVXH_Securit_CODE
-
8 -- where INVXH_date < to_DATE('25/02/2008','dd/mm/yyyy')
-
9 WHERE seq_NO = (select COUNT(*) from INVS_TXN_HEAD)
-
10 model
-
11 dimension by (seq_no)
-
12 measures (invxh_DATE
-
13 , INVXH_code
-
14 , INVXH_no
-
15 , invxh_TOTAL_qty
-
16 , balqty
-
17 , INVXH_net_AMOUNT_scy netAMT
-
18 , 0 balamt
-
19 , 0 balamt2
-
20 , 0 avgprice
-
21 , 0 cost)
-
22 rules (
-
23 balamt[seq_no is any] = nvl(balamt[cv() - 1], 0) +
-
24 decode(INVXH_code[cv()], 'BUY', netamt[cv()] , -(balamt[cv() -1] /
-
25 balqty[cv() -1] * invxh_TOTAL_qty[cv()]) ) ,
-
26 cost[seq_no is any] = decode(INVXH_code[cv()], 'SEL', balamt[cv() -1] /
-
27 balqty[cv() -1] * invxh_TOTAL_qty[cv()], 0),
-
28 avgprice[seq_no is any] = decode(INVXH_code[cv()], 'BUY', balamt[cv()] /
-
29 balqty[cv()] , avgprice[cv() - 1])
-
30* )
-
SQL> /
-
-
AVGPRICE SEQ_NO
-
-------------------- -------------
-
6.000
2 1589
If you are looking at simply fetching the record with maximum sequence value no then you can try using MAX(seq_no) instead of taking a COUNT
If you are looking at simply fetching the record with maximum sequence value no then you can try using MAX(seq_no) instead of taking a COUNT
didnt work actually,
and seq_no = (select MAX(seq_no) from INVS_TXN_HEAD)
it's still giving all the 5 rows.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ben McLaurin |
last post by:
I have a form with the info like First Name, Last name and a few other
things, based off a table (TABLE B). I have a function that opens a
list where the user can choose what records (multuple...
|
by: Michael Fay |
last post by:
There have been threads in this newsgroup explaining how to
tab out of a subform to the parent form -- without having to
use ctrl-tab (of which users might be unaware -- and at any
rate, they...
|
by: Nitin |
last post by:
Hi,
Without using sizeof, is there a way to get to know the size of any data
type on that OS ... ???
one way I could think of is to take diff of the addresses of two variables
defined...
|
by: Just D. |
last post by:
All,
Do we have a simple way to Create an object on the fly knowing just an
object type? The usual design-time way is to write a code something like
this:
CObjectType obj = new CObjectType();...
|
by: Neo Geshel |
last post by:
I have an Access DB, from which I am going to pull images. Each image
has an associated ID, but the ID's are not necessarily sequential (some
images may have been deleted, leaving gaps in the list...
|
by: Franck PEREZ |
last post by:
Hello,
I'm developing a small XML marshaller and I'm facing an annoying
issue. Here's some sample code:
########### My test application ############
class Foo(object):
#The class I'd like to...
|
by: Jason |
last post by:
I need to open a file for reading, but I only know part of it's name.
The file I want to read is in the format of xxx-yyyy-zzz.EXT
The last three digits of the file name are different on each...
|
by: rbutlerjr |
last post by:
Hi, I've racked my brain for the last few hours trying to figure
this one out. I have an array of language strings such as :
$lang = array();
$lang = 'hello';
$lang = 'goodbye';
$lang = '1st';...
|
by: Christof Warlich |
last post by:
Hi,
the subject says it all: I need to instantiate an array of objects
where each object "knows" its arrary index. So far, this is easy
as long as index is not a compile-time constant:
class ...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |