473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

knowing jusT the lasT row

2
Expand|Select|Wrap|Line Numbers
  1. SQL> ED
  2. Wrote file afiedt.buf
  3.  
  4.   1  select ROUND(avgprice, 10) avgprice, SeQ_no
  5.   2    from (select b.*,
  6.   3                 sum(decode(INVXH_code, 'BUY', invxh_TOTAL_QTY, -invxh_TOTAL_QTY)) OVER (ORDER BY INVXH_date) BALQTY,
  7.   4                 row_number() over (order by invxh_DATE) seq_no
  8.   5            from  INVS_TXN_HEAD b)
  9.   6  -- where INVXH_BROK_code = :INVXH_BROK_code
  10.   7  -- AND   INVXH_Securit_CODE = :INVXH_Securit_CODE
  11.   8  where   INVXH_date < to_DATE('25/02/2008','dd/mm/yyyy')
  12.   9  model
  13.  10  dimension by (seq_no)
  14.  11  measures (invxh_DATE
  15.  12  , INVXH_code
  16.  13  , INVXH_no
  17.  14  , invxh_TOTAL_qty
  18.  15  , balqty
  19.  16  , INVXH_net_AMOUNT_scy netAMT
  20.  17  , 0 balamt
  21.  18  , 0 balamt2
  22.  19  , 0 avgprice
  23.  20  , 0 cost)
  24.  21    rules (
  25.  22    balamt[seq_no is any]   = nvl(balamt[cv() - 1], 0) +
  26.  23                              decode(INVXH_code[cv()], 'BUY', netamt[cv()] , -(balamt[cv() -1] /
  27.  24                              balqty[cv() -1] * invxh_TOTAL_qty[cv()]) ) ,
  28.  25    cost[seq_no is any]     = decode(INVXH_code[cv()], 'SEL', balamt[cv() -1] /
  29.  26                              balqty[cv() -1] * invxh_TOTAL_qty[cv()], 0),
  30.  27    avgprice[seq_no is any] = decode(INVXH_code[cv()], 'BUY', balamt[cv()] /
  31.  28                              balqty[cv()] , avgprice[cv() - 1])
  32.  29*   )
  33. SQL> /
  34.  
  35.             AVGPRICE        SEQ_NO
  36. -------------------- -------------
  37.     2.22124210670000         1.000
  38.     2.24828175450000         2.000
  39.     2.22339370630000         3.000
  40.     2.19552193330000         4.000
  41.     2.17612187560000         5.000
  42.  
  43. 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"

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  select ROUND(avgprice, 10) avgprice, SeQ_no
  5.   2    from (select b.*,
  6.   3                 sum(decode(INVXH_code, 'BUY', invxh_TOTAL_QTY, -invxh_TOTAL_QTY)) OVER (ORDER BY INVXH_date) BALQTY,
  7.   4                 row_number() over (order by invxh_DATE) seq_no
  8.   5            from  INVS_TXN_HEAD b)
  9.   6  -- where INVXH_BROK_code = :INVXH_BROK_code
  10.   7  -- AND   INVXH_Securit_CODE = :INVXH_Securit_CODE
  11.   8  -- where   INVXH_date < to_DATE('25/02/2008','dd/mm/yyyy')
  12.   9  WHERE seq_NO = (select COUNT(*) from INVS_TXN_HEAD)
  13.  10  model
  14.  11  dimension by (seq_no)
  15.  12  measures (invxh_DATE
  16.  13  , INVXH_code
  17.  14  , INVXH_no
  18.  15  , invxh_TOTAL_qty
  19.  16  , balqty
  20.  17  , INVXH_net_AMOUNT_scy netAMT
  21.  18  , 0 balamt
  22.  19  , 0 balamt2
  23.  20  , 0 avgprice
  24.  21  , 0 cost)
  25.  22    rules (
  26.  23    balamt[seq_no is any]   = nvl(balamt[cv() - 1], 0) +
  27.  24                              decode(INVXH_code[cv()], 'BUY', netamt[cv()] , -(balamt[cv() -1] /
  28.  25                              balqty[cv() -1] * invxh_TOTAL_qty[cv()]) ) ,
  29.  26    cost[seq_no is any]     = decode(INVXH_code[cv()], 'SEL', balamt[cv() -1] /
  30.  27                              balqty[cv() -1] * invxh_TOTAL_qty[cv()], 0),
  31.  28    avgprice[seq_no is any] = decode(INVXH_code[cv()], 'BUY', balamt[cv()] /
  32.  29                              balqty[cv()] , avgprice[cv() - 1])
  33.  30*   )
  34. SQL> /
  35.  
  36.             AVGPRICE        SEQ_NO
  37. -------------------- -------------
  38.                              6.000
Aug 22 '08 #1
2 1589
amitpatel66
2,367 Expert 2GB
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
Aug 23 '08 #2
RHNShK
2
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.
Aug 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
4
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...
18
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...
2
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();...
11
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...
30
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...
4
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...
6
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';...
7
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 ...
0
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$) { } ...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.