SELECT MAX query
Hai Friends,
The following is my select query
SELECT MAX( MBLNR )
FROM ZMIGO
INTO TABLE IT_MAX.
Right now my Z table is empty. but when i debug the program it showing 1 entry and when i double the internal table there is no value and it is blank. why it is showing as 1 entry.
Hi,
Try using:-
DATA : v_mblnr TYPE zmigo-mblnr.
SELECT MAX( DISTINCT mblnr ) FROM zmigo INTO v_mblnr.
IF sy-subrc NE 0.
CLEAR v_mblnr.
ENDIF.
Hope this helps you.
Regards,
Tarun
Similar Messages
-
SQL query problem - select max (case... aggregate function)
Hi,
I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
select
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
Any ideas?Moved to more sutable forum, sorry.
-
How to select Max in a multi query?
Hi all,
I got this query:
select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
I want to get single row from the results of this query, so I may use MAX or MIN or where rownum<2.
How can I do this please....
I tried: SELECT MAX(select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2) from DUAL;
but I got syntax error :(
Please help....
Thanksselect DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
I want to get single row from the results of this querywhich row is correct row & why?
How many rows returned now? (Since we don't have your tables or data.)
Handle: KinsaKaUy?
Status Level: Newbie
Registered: Mar 9, 2011
Total Posts: 614
Total Questions: 168 (110 unresolved)
so many questions & so few answers.
How SAD!
Edited by: sb92075 on Aug 29, 2011 11:10 AM -
Problem selecting MAX YEAR MAX MONTH MAX DATE in one query
CREATE TABLE TEMP
C_INVOICE_ID NUMBER(10),
DIA NUMBER,
MES NUMBER,
ANO NUMBER,
SOCIO_NEGOCIO NVARCHAR2(60) NOT NULL,
PRODUCTO_NOM NVARCHAR2(60) NOT NULL,
M_PRODUCT_ID NUMBER(10),
CATEGORIA NVARCHAR2(60) NOT NULL,
COSTO NUMBER
INSERT INTO TEMP VALUES(10111,1,2,2010,'1585','ALURON 100MG X 30 TABLETAS',1530,15,1.15);
INSERT INTO TEMP VALUES(1015,15,2,2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);
INSERT INTO TEMP VALUES(5654,5,2,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);
INSERT INTO TEMP VALUES(15321,4,6,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
INSERT INTO TEMP VALUES(13548,8,6,2010,'1585','AMARYL 2MG X 15 TABLETAS',1531,15,4.3);
INSERT INTO TEMP VALUES(19456,31,4,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4);
INSERT INTO TEMP VALUES(116544,8,8,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
INSERT INTO TEMP VALUES(132,2,3,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.1);
INSERT INTO TEMP VALUES(168,15,1,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.9);
INSERT INTO TEMP VALUES(4898,7,4,2010,'1220','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
INSERT INTO TEMP VALUES(15132,25,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.4);
INSERT INTO TEMP VALUES(1684,18,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.3);
INSERT INTO TEMP VALUES(14988,8,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,2.9);
INSERT INTO TEMP VALUES(84941,8,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.1);
INSERT INTO TEMP VALUES(1155,7,4,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.7);
INSERT INTO TEMP VALUES(184,1,1,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
INSERT INTO TEMP VALUES(48994,8,4,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.7);
INSERT INTO TEMP VALUES(1465465,9,5,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
INSERT INTO TEMP VALUES(16,18,6,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
INSERT INTO TEMP VALUES(894886,20,4,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
CREATE TABLE TEMP
C_INVOICE_ID NUMBER(10),
DIA NUMBER,
MES NUMBER,
ANO NUMBER,
SOCIO_NEGOCIO NVARCHAR2(60) NOT NULL,
PRODUCTO_NOM NVARCHAR2(60) NOT NULL,
M_PRODUCT_ID NUMBER(10),
CATEGORIA NVARCHAR2(60) NOT NULL,
COSTO NUMBER
INSERT INTO TEMP VALUES(10111,1,2,2010,'1585','ALURON 100MG X 30 TABLETAS',1530,15,1.15);
INSERT INTO TEMP VALUES(1015,15,2,2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);
INSERT INTO TEMP VALUES(5654,5,2,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);
INSERT INTO TEMP VALUES(15321,4,6,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
INSERT INTO TEMP VALUES(13548,8,6,2010,'1585','AMARYL 2MG X 15 TABLETAS',1531,15,4.3);
INSERT INTO TEMP VALUES(19456,31,4,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4);
INSERT INTO TEMP VALUES(116544,8,8,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
INSERT INTO TEMP VALUES(132,2,3,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.1);
INSERT INTO TEMP VALUES(168,15,1,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.9);
INSERT INTO TEMP VALUES(4898,7,4,2010,'1220','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
INSERT INTO TEMP VALUES(15132,25,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.4);
INSERT INTO TEMP VALUES(1684,18,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.3);
INSERT INTO TEMP VALUES(14988,8,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,2.9);
INSERT INTO TEMP VALUES(84941,8,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.1);
INSERT INTO TEMP VALUES(1155,7,4,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.7);
INSERT INTO TEMP VALUES(184,1,1,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
INSERT INTO TEMP VALUES(48994,8,4,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.7);
INSERT INTO TEMP VALUES(1465465,9,5,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
INSERT INTO TEMP VALUES(16,18,6,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
INSERT INTO TEMP VALUES(894886,20,4,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
I have this query so far,
SELECT
MAX (TEMP.COSTO) COSTO,
TEMP.M_PRODUCT_ID,
TEMP.ANO
FROM TEMP TEMP
INNER JOIN(
SELECT MAX(ANO) ANO, M_PRODUCT_ID
FROM TEMP I
GROUP BY M_PRODUCT_ID
) LA ON LA.ANO = TEMP.ANO AND LA.M_PRODUCT_ID = TEMP.M_PRODUCT_ID
GROUP BY
TEMP.M_PRODUCT_ID,
TEMP.ANO
but my intention is not to have the max cost, my intention is to query in this order
first i need to select distinct m_product_id then
for every m_product_id i need to
filter max (ano) then filter max (mes) then filter max (dia)
I need the result set like this.
C_INVOICE_ID DIA MES ANO SOCIO PRODUCTO_NOM M_PRODUCT_ID CATERGORIA COSTO
1015 15 2 2010 1520 ALURON 100MG X 30 TABLETAS 1530 15 2.15
5654 5 2 2010 1520 AMARYL 2MG X 15 TABLETAS 1531 15 4.2
15132 25 9 2010 1585 AMOXAL 250MG X 75ML SUSPENSION 1534 15 3.4
please i really apritiated any help, thanks pd:i'm using oracle 9iHi,
Thanks for posting the CREATE TABLE and INSERT statements. Why are there two tables, and two sets of data? Was that a mistake?
Sorry, I don't uderstand the problem.
For m_product_id=1531, for example, why do you want
INSERT INTO TEMP VALUES(5654, 5, 2, 2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);selected, and not
INSERT INTO TEMP VALUES(116544, 8, 8, 2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);Both rows have ano=2010, so don't you want the one with the higher mes (8 > 2)?
I think what you'll want is a Top-N Query , something like this:
WITH got_r_num AS
SELECT temp.* -- or list columns you want
, RANK () OVER ( PARTITION BY m_product_id
ORDER BY ano DESC NULLS FIRST
, mes DESC NULLS FIRST
, dia DESC NULLS FIRST
) AS r_num
FROM temp
-- WHERE ... -- any filtering goes here
SELECT * -- or list all columns except r_num
FROM got_r_num
WHERE r_num = 1
;What if there's a tie? For example, if you add another row to the sample data:
INSERT INTO TEMP VALUES(9876, 15,2, 2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);The query above would include both c_invoice_id=9876 and 1015. If you want just one of those rows, add more expressions to the analytic ORDER BY clause and/or use ROW_NUMBER instead of RANK. -
How to : SELECT MAX(EmpID) / count(*) in SELECT Query
Hi,
I like to find out the Maximum of the EmpID that is in the DB table.
So I need to perform a select Query:
Select MAX(EmpID) from EmpTable
or Select Count(*) from EmpTable
<StatementName>
<dbTableName action=SELECT>
<table>realDbTableName</table>
<access>
<??? />
</access>
</dbTableName>
</StatementName>
I cannot type MAX(EmpID) or count(*) as access element
So what should I mention in the Access?
Thanks & regards,
Siva Maranani.if 0CALDAY is used as a characteristic then you have to convert that as a key figure using a replacement path variable.
Please see the below link for changing 0CALDAY as a key figure using Replacement path
http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
https://websmp106.sap-ag.de/~sapdownload/011000358700001963972003E/HowToCalcWithAttr.pdf
Now you have to create an exception "Top N Rows" based on the replacement path variable created above.
This will solve your problem.
Regs
Gopi.
Award points if it helps ... -
How to use select max and min query..
hi gurus,
we have got a custom report for develoment.
the report has to fetch the max and min salarys department wise....
how to pick up max & min sal ansal from table pa0008.Hi,
Try the following
select max(sal)
min(sal)
from <database table>
into <internal table>
group by department
where <where condition>.
Here we assume that sal is the field holding the salary and department is the name of the field in the database table. Where condition is optional.
Hope this helps.
Regards,
Sachin -
Select Max and ResultSet Problem With Access
The following code is producing a 'null pointer excepetion' error and I know why it is occurring I just do not know how to fix the problem.
Basically I want to automitically generate a unique ID that is one number higher than the max ID (data is stored within an Access database). The ID field is made up of first and last initial taken from parsing previous login info ('JS-01', 'JS-02', ect.). If there are no IDs in the database that match your login info I want to set the new ID equal to 'JS-01' if your login is 'James Smith' for example.
The problem is explained within the code below.
<%
//define resultset and statement
ResultSet rss=null;
ResultSet rs=null;
Statement stmt=null;
//HERE IS WHERE YOU PARSE THE LOGIN INFO
String finitial = (String)session.getAttribute("vfirst");//vfirst=JIM
String linitial = (String)session.getAttribute("vlast");//vlast=SMITH
char f = finitial.charAt(0);
char n = linitial.charAt(0);
String sID = f+""+n;//NOW sID CONTAINS 'JS'
try {
//Using the current database connection create a statement
stmt=con.createStatement();
//QUERY TO SELECT MAX ID
//NOTE: CURRENTLY THERE ARE NO IDs LIKE 'JS' IN THE DATABASE !!!!!!
String sql="SELECT Max(ID) As MaxID FROM tblError Where ID LIKE '%"+sID+"%'" ;
rs = stmt.executeQuery(sql);
String newID;
//HERE THE RESULT SET SHOULD BE NULL BUT IT IS NOT. I KNOW THIS BECAUSE WHEN I REPLACE String iID WITH A LITERAL LIKE 'JS-03' THE LOGIC WILL EXECUTE CORRECTLY AND GIVE ME 'JS-04'. IF I LEAVE THE CODE LIKE IT IS THEN I GET THE NULL POINTER VALUE ERROR BECAUSE YOU CANNOT RESOLVE "MaxID" WHEN THE RESULT SET IS NULL. IF THE RESULT SET IS NULL IT SHOULD NOT EVEN EXECUTE ANY OF THIS CODE WITHIN THE 'if' STATEMENT, BUT IT IS. SO BASICALLY JSP IS LEAVING ME WITH A MAJOR OXYMORON AND I WOULD APPRECIATE ANY ADVICE THAT WOULD HELP ME SOLVE THIS PROBLEM.
if(rs.next()){
String iID = rs.getString("MaxID");
String letters = iID.substring(0,3);
int numbers = Integer.parseInt(iID.substring(3,5));
numbers = numbers + 1;
if(numbers < 10){
newID = letters + "0" + numbers;}
else{
newID = letters + numbers;
else{//IF THERE IS NO RESULT SET THAN THE ID SHOULD BE 'JS-01'
newID = sID + "-01";
%>
Because this an Access database I cannot use any null exception functions such as NVL or COALESCE which are specific to Oracle and SQL Server I beleive.The max() will return a result set, even if the max value is null.
You should check to see if iID is null.
if(rs.next())
String iID = rs.getString("MaxID");
if (iID == null)
newID = sID + "-01";
else
String letters = iID.substring(0,3);
... etc ...
} -
ResultSet Select MAX() Problem
Im using mySQL and when i write the following query :
SELECT MAX(attribute) FROM table;
and theres no records in the table i cant know what it returns ... my problem is i want to get the max() number
<code>
resultSet = connectivity.statement.executeQuery("SELECT MAX(number) FROM urls");
resultSet.next();
if(resultSet.getObject(1) != null)
.... Do certain things
else
....Do other
</code>
an SQLexcecption is thrown from this line :
if(resultSet.getObject(1) != null)
so how can i solve it ??!java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3908)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5699)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:353)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:410)
at indexer.Indexer.insertNewRecords(Indexer.java:80)
at indexer.Indexer.startIndexing(Indexer.java:31)
at jranker1.JRanker.writeToDB(JRanker.java:187)
Its an SQL Exception ... -
Post Author: Aron Sereny
CA Forum: Data Connectivity and SQL
i want to limit the result set of the select to only the latest invoice for a given client.
so, I was hoping to use use
invoice.num = (select max( invoice.num).....
in the record selection...but it does not like my sub select in the where clause...any work around for this?
in other words...my select returns
1002 1
1002 2
1002 3
1001 1
998 1
998 2
but i only want the first 3 records (invNum= 1002, the max invNum for this client)
using CR XI, thanks for any insightPost Author: Aron Sereny
CA Forum: Data Connectivity and SQL
i am working with MS sql 2000
my rpt returns
102 1
102 2
101 1
i would like to limit the result set to the 102 id (the largest, most recent ID)
in query analyzer my select works fine with the where clause something like:
where....
and id = (select max (id) from.....)
crystal does not like the sub select in the where clause (select criteria)
thanks for any help -
Sub-Select Count query breaking TOAD
Oracle 10.2.0.4.0
Running TOAD 9.1
I am running some SQL on our eBusiness Suite:
SELECT pha.segment1
, pha.type_lookup_code
, (SELECT COUNT(DISTINCT pha2.po_header_id)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) po_count
, (SELECT MAX(pha2.creation_date)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) latest_cpa_po
FROM po.po_headers_all pha
, po.po_vendors pv
, po.po_vendor_sites_all pvsa
WHERE pha.vendor_id = pv.vendor_id
AND pha.vendor_site_id = pvsa.vendor_site_id
-- AND pv.VENDOR_NAME LIKE 'H%'
AND pha.vendor_id = 98
AND pha.type_lookup_code = 'CONTRACT'
AND pha.org_id IN(7041, 7042);The above query runs quicky (approx. 1 second). If I take out the AND pha.vendor_id = 98 then the query takes a few minutes to run.
When I try to export it, or scroll down to view > 500 rows, TOAD crashes.
I know this isn't a TOAD forum, but I think that this is probably an issue with my no doubt rubbish SQL.
If I take out this sub-select, then the problem doesn't happen:
, (SELECT COUNT(DISTINCT pha2.po_header_id)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) po_countHowever, I can't work out a better way of getting the data I need.
The sub-select counts POs which have been raised where the contractID on the PO line is the same as the PO Header ID from the main query.
Any advice please, on what I could do to sort this out would be much appreciated.
Thanks!Hi,
It looks like you can replace both scalar sub-queries with a join, like this:
WITH header_lines_summary AS
SELECT pla.contract_id
, COUNT (DISTINCT pha2.po_header_id) AS po_count
, MAX (pha2.creation_date) AS latest_cpa_po
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
GROUP BY pla.contract_id
) -- Everything up to this line is new
SELECT pha.segment1
, pha.type_lookup_code
, hls.po_count -- Changed
, hls.latest_cpa_po -- Changed
FROM po.po_headers_all pha
, po.po_vendors pv
, po.po_vendor_sites_all pvsa
, header_lines_summary hls -- New
WHERE pha.vendor_id = pv.vendor_id
AND pha.vendor_site_id = pvsa.vendor_site_id
AND pha.po_header_id = hls.contract_id (+) -- New
-- AND pv.VENDOR_NAME LIKE 'H%'
AND pha.vendor_id = 98
AND pha.type_lookup_code = 'CONTRACT'
AND pha.org_id IN (7041, 7042);Aside from the sub-query (which is entirely new), the query above is just what you posted, with 2 lines changed and 2 lines added, as marked.
This should be more efficient, but I don't know for certain that it will solve the Toad problem.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
It never hurts to say what version of Oracle you're using. -
Hello all,
I have two table table1 and table2 with two columns
Table1 : Employee ID,Value
Table2 : UseID, value.
Now I want to create query which use the maximum value of any one value
SELECT t1.Employeeid,t2.UseID from table1 t1,table2 t2
Where t1.Employeeid=t2.userid where Employeeid=max(Employeeid,UseID)
Is it possible ?This is what you wanted, right!
select max(empid)
from ( select empid
from table1
union all
select userid
from table2
)And what i was saying is that
SELECT col1,col2,col3
FROM table1
UNION ALL
SELECT col1,col2,null
FROM table2;That is number of columns in both SELECT list should be same.
Edited by: Mahanam on Dec 28, 2010 2:22 AM -
I have the following recordset that includes a Patient Identification Number along with a Date of Service:
PatientID DOS
====== ======
11111 1/1/2015
11111 1/5/2015
33333 1/3/2015
22222 1/2/2015
11111 2/1/2015
22222 1/1/2015
11111 1/2/2015
33333 2/10/2015
11111 2/11/2015
22222 1/1/2015
I need a query that shows the MAX DOS for each patient. For example:
PatientID DOS
====== ======
11111 2/11/2015
22222 1/2/2015
33333 2/10/2015
Is this possible?
Thanks.t1 and t2 is alias for table
SELECT
PatientID ,( select max ( DOS ) from Patient as t2 where t2 . PatientID = t1.PatientID ) DOS
FROM
Patient as t1
group by PatientID
I only have one table in select and subselect
Uma imagem vale mais do que mil palavras, mas ocupa 3 mil vezes mais espaço em disco -
Using SELECT MAX to default to certain days
Gurus,
Right now, I use SELECT MAX("File Date"."Date")FROM "Subject Area" to pull the most recent date available. I'd like for this to pull the last two or three days of data available. Any suggestions?
I have this set under a report filter for the analysis. Thanks in advance!Try this
SELECT File Date.Date saw_0, TOPN(File Date.Date, 3) saw_1, Facts."#Sales" saw_2 FROM "Subject Area" ORDER BY saw_0
Let me know updates
Edited by: Srini VEERAVALLI on May 6, 2013 5:10 PM
Your initial post talks about logical query from OBIEE, so I've logical query. try to put that in answers instead of running in Toad or sql developer etc..
Edited by: Srini VEERAVALLI on May 6, 2013 8:20 PM -
SELECT MAX(field) / SELECT MIN(field) return wrong values
Hi,
I have the query:
Select
MAX(b1.time_s) as time_s
From
BUSINESS_INVOCATIONS b1
Where
b1.time_s >= 1219217034000
AND b1.rec_sess_id = 2197756621378027521
AND b1.comp_id IN ( Select id From J2EE_CONFIGURATION_BEAN Where j2eeApplicationsTableId = 378302371920347137 )
This return the MAX value of the comp_id and not the MAX value of the b1.time_s
looks like there is a BUG in MAXDB when i have a join of two tables the MAX/MIN functions works on the wrong fields!
If i change the query to be:
Select
max(b1.time_s) as time_s
From
BUSINESS_INVOCATIONS b1,
J2EE_CONFIGURATION_BEAN jcb
Where
b1.time_s >= 1219217034000
AND b1.rec_sess_id = 2197756621378027521
AND jcb.j2eeApplicationsTableId = 378302371920347137
AND b1.comp_id = jcb.id
The MIN/MAX functions works good and return the right value
Pleasehelp me to find what is the problem and if any one already have a solution.
Thanks,
YosefDta for BUSINESS_INVOCATIONS tabel:
ID,CLASS_TYPE,M_TIME,FUNCTIONENTRYID,TOP_PARENT,START_TIME,TIME_S,COMP_ID,REC_SESS_ID,PARENT,HTTP_SESSION,INVOCATION_HASH_CODE,MINOR_INVOCATION,TRANSACTION_ID,USER_TRACING_COOKIE,TRACINGTYPE
2089670230321135617,H,1219738865499,1387108688451338241,2089670230321135617,1219217053734,1219217053734,414331168939311111,2197756621378027521,(null),2179742222868545537,-1238173181,GET,null,null,-1
2089670230321135618,H,1219738865499,1387108688451338242,2089670230321135618,1219217071156,1219217071156,414331168939311108,2197756621378027521,(null),2179742222868545538,-628203986,GET,null,null,-1
2089670230321135619,H,1219738865499,1387108688451338279,2089670230321135619,1219217073531,1219217073531,414331168939311112,2197756621378027521,(null),2179742222868545538,545948335,GET,null,null,-1
2089670230321135620,H,1219738865499,1387108688451338284,2089670230321135620,1219217075671,1219217075671,414331168939311119,2197756621378027521,(null),2179742222868545538,1958406838,GET,null,null,-1
2089670230321135621,H,1219738865499,1387108688451338289,2089670230321135621,1219217077359,1219217077359,414331168939311106,2197756621378027521,(null),2179742222868545538,-2089005650,GET,null,null,-1
2089670230321135622,H,1219738865499,1387108688451338292,2089670230321135622,1219218442312,1219218442312,414331168939311115,2197756621378027521,(null),2179742222868545538,-1298180580,GET,null,null,-1
2089670230321135623,H,1219738865499,1387108688451338297,2089670230321135623,1219218467765,1219218467765,414331168939311107,2197756621378027521,(null),2179742222868545538,1318337921,GET,null,null,-1
2107684628830617601,E,1219738865515,1387108688451338244,2089670230321135618,1219217071171,1219217071171,324259176391901185,2197756621378027521,2089670230321135618,2179742222868545538,586868856,(null),(null),(null),-1
2107684628830617602,E,1219738865515,1387108688451338281,2089670230321135619,1219217073531,1219217073531,324259176391901185,2197756621378027521,2089670230321135619,2179742222868545538,1886325459,(null),(null),(null),-1
2107684628830617603,E,1219738865515,1387108688451338286,2089670230321135620,1219217075671,1219217075671,324259176391901185,2197756621378027521,2089670230321135620,2179742222868545538,-550916224,(null),(null),(null),-1
2107684628830617604,E,1219738865515,1387108688451338291,2089670230321135621,1219217077359,1219217077359,324259176391901185,2197756621378027521,2089670230321135621,2179742222868545538,1676270392,(null),(null),(null),-1
2107684628830617605,E,1219738865515,1387108688451338294,2089670230321135622,1219218442312,1219218442312,324259176391901185,2197756621378027521,2089670230321135622,2179742222868545538,-2074647744,(null),(null),(null),-1
2107684628830617606,E,1219738865515,1387108688451338299,2089670230321135623,1219218467765,1219218467765,324259176391901185,2197756621378027521,2089670230321135623,2179742222868545538,63795915,(null),(null),(null),-1
3278620531946946561,T,1219738865483,1387108688451338291,2089670230321135621,1219217077359,1219217077359,2828260569209896968,2197756621378027521,2107684628830617604,2179742222868545538,-1511714853,java.lang.ArithmeticException,(null),(null),18
Daa for J2EE_CONFIGURATION_BEAN Table:
select * from IDENTIFY.J2EE_CONFIGURATION_BEAN
ID,J2EEAPPLICATIONSTABLEID,J2EEAPPLICATIONID,J2EECOMPONENTID
180144094616485889,0,0,0
180144094616485890,0,0,0
180144094616485891,0,0,0
180144094616485892,0,0,0
180144094616485893,378302478220787713,0,0
180144094616485894,0,0,0
306244884182859777,378302478220787713,360288079711305731,306244884182859777
324259282692341761,378302478220787713,360288079711305731,306244884182859777
360288079711305729,378302478220787713,360288079711305729,0
360288079711305730,378302478220787713,360288079711305730,0
360288079711305731,378302478220787713,360288079711305731,0
360288079711305732,378302478220787713,360288079711305732,0
360288079711305733,378302478220787713,360288079711305733,0
360288079711305734,378302478220787713,360288079711305734,0
414331275239751681,378302478220787713,360288079711305731,594475260334571522
414331275239751682,378302478220787713,360288079711305731,594475260334571522
414331275239751683,378302478220787713,360288079711305731,594475260334571522
414331275239751684,378302478220787713,360288079711305731,594475260334571522
414331275239751685,378302478220787713,360288079711305731,594475260334571522
414331275239751686,378302478220787713,360288079711305731,594475260334571522
414331275239751687,378302478220787713,360288079711305731,594475260334571522
414331275239751688,378302478220787713,360288079711305731,594475260334571522
414331275239751689,378302478220787713,360288079711305731,594475260334571522
414331275239751690,378302478220787713,360288079711305731,594475260334571522
414331275239751691,378302478220787713,360288079711305731,594475260334571522
414331275239751692,378302478220787713,360288079711305731,594475260334571522
414331275239751693,378302478220787713,360288079711305731,594475260334571522
414331275239751694,378302478220787713,360288079711305731,594475260334571522
414331275239751695,378302478220787713,360288079711305731,594475260334571522
540432064806125569,378302478220787713,360288079711305732,594475260334571523
540432064806125570,378302478220787713,360288079711305732,594475260334571523
540432064806125571,378302478220787713,360288079711305732,594475260334571523
540432064806125572,378302478220787713,360288079711305732,594475260334571523
540432064806125573,378302478220787713,360288079711305732,594475260334571523
540432064806125574,378302478220787713,360288079711305732,594475260334571523
540432064806125575,378302478220787713,360288079711305734,594475260334571524
540432064806125576,378302478220787713,360288079711305734,594475260334571524
576460861825089537,378302478220787713,360288079711305730,576460861825089537
576460861825089538,378302478220787713,360288079711305731,576460861825089538
576460861825089539,378302478220787713,360288079711305732,576460861825089539
576460861825089540,378302478220787713,360288079711305733,576460861825089540
576460861825089541,378302478220787713,360288079711305734,576460861825089541
594475260334571521,378302478220787713,360288079711305729,594475260334571521
594475260334571522,378302478220787713,360288079711305731,594475260334571522
594475260334571523,378302478220787713,360288079711305732,594475260334571523
594475260334571524,378302478220787713,360288079711305734,594475260334571524
2810246277000855553,378302478220787713,360288079711305729,2810246277000855553
2810246277000855554,378302478220787713,360288079711305729,2810246277000855554
2810246277000855555,378302478220787713,360288079711305729,2810246277000855555
2810246277000855556,378302478220787713,360288079711305729,2810246277000855556
2810246277000855557,378302478220787713,360288079711305729,2810246277000855557
2810246277000855558,378302478220787713,360288079711305729,2810246277000855558
2810246277000855559,378302478220787713,360288079711305729,2810246277000855559
2828260675510337537,378302478220787713,360288079711305729,2846275074019819521
2828260675510337538,378302478220787713,360288079711305729,2846275074019819521
2828260675510337539,378302478220787713,360288079711305729,2846275074019819521
2828260675510337540,378302478220787713,360288079711305729,2846275074019819521
2828260675510337541,378302478220787713,360288079711305729,2846275074019819521
2828260675510337542,378302478220787713,360288079711305729,2846275074019819521
2828260675510337543,378302478220787713,360288079711305729,2846275074019819521
2828260675510337544,378302478220787713,360288079711305729,2846275074019819521
2828260675510337545,378302478220787713,360288079711305729,2846275074019819521
2828260675510337546,378302478220787713,360288079711305729,2846275074019819521
2828260675510337547,378302478220787713,360288079711305729,2846275074019819521
2828260675510337548,378302478220787713,360288079711305729,2846275074019819521
2828260675510337549,378302478220787713,360288079711305729,2846275074019819521
2828260675510337550,378302478220787713,360288079711305729,2846275074019819521
2828260675510337551,378302478220787713,360288079711305729,2846275074019819521
2828260675510337552,378302478220787713,360288079711305729,2846275074019819521
2846275074019819521,378302478220787713,360288079711305729,2846275074019819521
3152519848681013249,378302478220787713,360288079711305729,3152519848681013249
3152519848681013250,378302478220787713,360288079711305730,3152519848681013250
3152519848681013251,378302478220787713,360288079711305731,3152519848681013251
3152519848681013252,378302478220787713,360288079711305732,3152519848681013252
3152519848681013253,378302478220787713,360288079711305733,3152519848681013253
3152519848681013254,378302478220787713,360288079711305734,3152519848681013254
3170534138742571009,0,0,0
3170534138742571010,0,0,0
3170534247190495233,0,0,0
3170534247190495234,0,0,0
3602879811418062849,378302478220787713,360288079711305729,594475260334571521
Hope this will help:)
Thanks,
Yosef -
HELP: SELECT MAX( Exp1, Exp2)
SELECT MAX( 1,2,3) FROM DUAL:
Should return 3 but it does not. Each element 1 2 3 is an expression. According to "Oracle 9i SQL Ref" MAX uses standard sql Expressions which Includes an Expression List which is delimited by "," Since SELECT MAX(2) FROM DUAL Returns 2 it should iterate.
I have a table
ID: VAL1: VAL2
I want to query and return 2 columns
ID: MAX(VAL1,VAL2)
I know I probably forgot something stupid.
Thank you for any help.max finds the maximum value from one column (or expression) from multiple rows.
so this will work:
select max(x) from (
select 1 x from dual
union
select 2 from dual
union
select 3 from dual
to find the maximum value from different columns from one row use "greatest".
select greatest(1,2,3) from dual;
Maybe you are looking for
-
Unable to display table data in Review View
Hi Experts, I have one main view and one review View .In my main view i have one table (Normal Table) and several other input feilds and text views.... If i click on review button in my main view, am able to see all the data in review view except tab
-
My functional people are getting this error along with CX_SY_IMPORT_MISMATCH_ERROR. The problem is occurring in CL_HR_PAY_RESULT_US - IMPORT_FROM_TABLE. The reason for the exception is: When attempting to import
-
My apple TV has stopped working completely. Just a flashing Amber light
My Apple TV has stopped working. When it is turned on I just get a flashing amber light and it does not turn blue as normal. It doesn't connect wirelessly to my Mac and it doesn't connect to the TV. I do not get the setup menu and it is totally un
-
SAML AS JAVA user mapping. Can table VUSREXTID On AS ABAP be leveraged?
The documentation on the SAML AS java user mapping refers to Mapping SAML Principals to SAP J2EE Engine User IDs - User Authentication and Single Sign-On - SAP Library custom development. In my case the users are managed on the AS ABAP system. Can I
-
Problems Installing Mouse to T41
Greetings, I recently acquired a T41. A computer savvy family member reformatted the machine, installed the OS w/ all updates. Running Windows XP Pro. I am having a hard time installing a Microsoft Basic Optical Mouse. I downloaded and instal