Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: How to put a TOP 1 in a select
This is an example of the information.
I forgot to mention that in each company we have supermarkets called
in the system Locations. So when I do this query I have to return per item the
total of sales in the las two week, the day that we sale more per
supermarket
Item trans_date
Quantity Location
AM -1 TJU240570017 6/3/2003 12:00:00 AM -1 TJU240570018 5/29/2003 12:00:00 AM -4 TJU020570018 5/31/2003 12:00:00 AM -3 TJU020570018 5/28/2003 12:00:00 AM -2 TJU020570018 5/30/2003 12:00:00 AM -2 TJU020570018 6/3/2003 12:00:00 AM -2 TJU020570018 6/2/2003 12:00:00 AM -2 TJU020570018 6/1/2003 12:00:00 AM -1 TJU020570018 5/30/2003 12:00:00 AM -6 TJU240570018 6/1/2003 12:00:00 AM -6 TJU240570018 6/2/2003 12:00:00 AM -5 TJU240570018 6/3/2003 12:00:00 AM -3 TJU240570018 5/31/2003 12:00:00 AM -2 TJU240570018 5/28/2003 12:00:00 AM -1 TJU240570018 6/9/2003 12:00:00 AM -4 TJU310570019 6/2/2003 12:00:00 AM -3 TJU240570019 5/28/2003 12:00:00 AM -1 TJU240570019 6/9/2003 12:00:00 AM -1 TJU310570020 6/3/2003 12:00:00 AM -2 TJU020570020 5/31/2003 12:00:00 AM -1 TJU020570020 6/2/2003 12:00:00 AM -1 TJU020570020 6/1/200312:00:00 AM -1 TJU24
Item trans_date sum(
Quantity ) Location
AM -1 TJU240570017 6/3/2003 12:00:00 AM -1 TJU240570018 5/29/2003 12:00:00 AM -16 TJU020570018 5/30/200312:00:00 AM (or 6/1/2003 12:00:00
12:00:00 AM -4 TJU310570019 6/2/2003 12:00:00 AM -4 TJU240570019 6/9/2003 12:00:00 AM -1 TJU310570020 6/3/2003 12:00:00 AM -4 TJU020570020 6/1/2003 12:00:00 AM -1 TJU24
POINT-SIZE="9">SELECT<FONT face="Courier New" color=#000000 POINT-SIZE="9"> <FONT face="Courier New" color=#0000ff POINT-SIZE="9">distinct<FONT face="Courier New" color=#000000 POINT-SIZE="9"> a.ITEM, a.TRANS_DATE,a.LOCATION,
POINT-SIZE="9"> (
face="Courier New" color=#0000ff POINT-SIZE="9">SELECT<FONT face="Courier New" color=#000000 POINT-SIZE="9"> ITEM, LOCATION,<FONT face="Courier New" color=#0000ff POINT-SIZE="9">SUM<FONT face="Courier New" color=#000000 POINT-SIZE="9">(QUANTITY) tot_QUANTITY,MAX<FONT
<FONT face="Courier New" color=#000000
POINT-SIZE="9"> <FONT face="Courier New"
color=#008000 POINT-SIZE="9">-- and LOCATION='TJU02'
<FONT
face="Courier New" color=#000000
POINT-SIZE="9"> <FONT
face="Courier New" color=#0000ff POINT-SIZE="9">AND<FONT
face="Courier New" color=#000000 POINT-SIZE="9">
TRANS_DATE <FONT face="Courier New" color=#0000ff
POINT-SIZE="9">BETWEEN<FONT face="Courier New" color=#000000 POINT-SIZE="9"> (CURRENT_DATE-14) <FONT face="Courier New" color=#0000ff POINT-SIZE="9">AND
POINT-SIZE="9">
POINT-SIZE="9">'57'<FONT face="Courier New" color=#000000 POINT-SIZE="9">
face="Courier New" color=#0000ff POINT-SIZE="9">GROUP<FONT face="Courier New" color=#000000 POINT-SIZE="9"> <FONT face="Courier New" color=#0000ff POINT-SIZE="9">BY<FONT face="Courier New" color=#000000 POINT-SIZE="9"> ITEM ,LOCATION
face="Courier New" color=#0000ff POINT-SIZE="9">WHERE<FONT face="Courier New" color=#000000 POINT-SIZE="9"> a.ITEM=<FONT face="Courier New" color=#ff0000 POINT-SIZE="9">'0570018'<FONT face="Courier New" color=#000000 POINT-SIZE="9"> <FONT face="Courier New"color=#0000ff POINT-SIZE="9">AND<FONT face="Courier New" color=#000000 POINT-SIZE="9"> a.ITEM = b.ITEM
face="Courier New" color=#0000ff POINT-SIZE="9">AND<FONT face="Courier New" color=#000000 POINT-SIZE="9"> a.TRANS_DATE <FONT face="Courier New" color=#0000ff POINT-SIZE="9">BETWEEN<FONT face="Courier New" color=#000000POINT-SIZE="9"> (CURRENT_DATE-14) <FONT face="Courier New" color=#0000ff POINT-SIZE="9">AND
valid.
Jayadas {PBSG}"
<[EMAIL PROTECTED]
cc:
Subject: RE: How to put a TOP 1 in a select
by: [EMAIL PROTECTED] .com
04:25
to ORACLE-LThis query would give you the total quantity sold in thepast two weeks and the date on which maximum number wassold, for each item ...SELECT a.item,
ICTRANS WHERE company = 2000 AND trans_date
AND doc_type = 'IS' AND reason_code =