SELECT MAX(FILE_VERSION)
I have put the following part of code in a WHERE clause:
AND PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IN
(SELECT MAX(FILE_VERSION)
FROM PCMS_CHDOC_ACTION_DESC PCMS_CHDOC_ACTION_DESC_4
WHERE PCMS_CHDOC_ACTION_DESC_4.CH_UID = PCMS_CHDOC_DATA_2.CH_UID AND PCMS_CHDOC_ACTION_DESC_4.CH_DOC_ID = PCMS_CHDOC_DATA_2.CH_DOC_ID)...but for the records where the FILE_VERSION is null or doesn't exist doesn't retrieve any record.
There is a way to write it such is possible to retrieve also the records which are null?
AND (PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IN
(SELECT MAX(FILE_VERSION)
FROM PCMS_CHDOC_ACTION_DESC PCMS_CHDOC_ACTION_DESC_4
WHERE PCMS_CHDOC_ACTION_DESC_4.CH_UID = PCMS_CHDOC_DATA_2.CH_UID
AND PCMS_CHDOC_ACTION_DESC_4.CH_DOC_ID = PCMS_CHDOC_DATA_2.CH_DOC_ID
) OR PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IS NULL)<i>
or doesn't exist doesn't retrieve any record.</i>
What do you mean by that?
*009*
Edited by: 009 on Apr 16, 2010 12:14 AM
Similar Messages
-
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 ...
} -
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.
-
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 -
Select Max record for the report
Post Author: ROMZILBER
CA Forum: WebIntelligence Reporting
Hello,
Here is our problem we have history data on a table like
Example
Data:
11111 bbb 12/31/2004
11111 nnn 12/31/2005
11111 ddd 12/31/2007
On a report we only need to display the most current record (based on a date).
11111 ddd 12/31/2007
How can we do that, we have try to create subquery but it does not allowed to enter logic for the max date for the same id. So we are kind of stuck, I am more then sure this would be a very common conditions specially for data warehousing.
we are on Oracle 10g
Thank you for all your help.Post Author: ROMZILBER
CA Forum: WebIntelligence Reporting
To create a view is not a problem, supporting it is a different story
But we have find a solution, you were correct about the filter. I just did not know you can put the whole subselect in a filter
but here is a logic for the filter if someone would come up with the same problem
tablename.NNNN_PROOF_DT = (SELECT MAX(X.NNNN_PROOF_DT) FROM tablename X WHERE tablename.NNNN_CLAIM_NUMBER = X.NNNN_CLAIM_NUMBER AND tablename.NNNN_LINE_CD = X.NNNN_LINE_CD)
please let me know if you have any questions.
sorry I am new to this so please do not take any offense -
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 -
Same select max is very slow in one program but fast in another
Hi,
I have a report that becomes very slow these few months. I used SQL trace for the report and found out its these codes that slow down the report:
SELECT MAX( mkpf~budat )
FROM mkpf
INNER JOIN mseg
ON mseg~mblnr = mkpf~mblnr AND mseg~mjahr = mkpf~mjahr
INTO posting_date
WHERE mseg~werks = w_matl-batch_reservations-werks
AND mseg~charg = w_matl-batch_reservations-charg
AND mseg~bwart IN ('261', 'Z61').
The thing is these codes have been used in different system, DEV, QAS, and PRD. But only in PRD it is very slow, other systems are pretty fast.
I even created a local copy of that report in PRD, with the same code. The local file runs fast and perfectly. But the original code is just slow.
Just wondering if anybody met this problem too? any ideas??Hi Liu,
Index creation is not a advisable solution.Please follow the existing indexes by adding Mandt field.
Try like this
SELECT MAX( mkpf~budat )
FROM mkpf
INNER JOIN mseg
ON mseg~mblnr = mkpf~mblnr AND mseg~mjahr = mkpf~mjahr
INTO posting_date
WHERE mseg~mandt = sy-mandt
AND mkpf~mandt = sy-mandt
AND mseg~werks = w_matl-batch_reservations-werks
AND mseg~charg = w_matl-batch_reservations-charg
AND mseg~bwart IN ('261', 'Z61').
Hope it will be helpful.
Regards,
Kannan -
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 -
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. -
Report counterpart sample for field = select(max)
Post Author: JuneCruz
CA Forum: Crystal Reports
Hi Guys,
This the contenct of my table.
NFstCol NSndCol NTrdCol -
1 One 12 One 13 One 14 Two 15 Two 16 Two 17 One 28 One 29 One 210 One 311 One 312 One 316 Two 217 Two 218 Two 219 Four NULL20 Four NULL21 Four NULL
Now I want to display the records all records that have the maximum ntrdcol group by nsndcolso the output should be. Can this be done without using view, command as source for the database, or a subreport ?thanks.
NfstCol NtrdColOne
10 3 11 3 12 3
Two 16 2 17 2 18 2
Four 19 null 20 null 21 null
Again. Thanks guys.Post Author: ROMZILBER
CA Forum: WebIntelligence Reporting
To create a view is not a problem, supporting it is a different story
But we have find a solution, you were correct about the filter. I just did not know you can put the whole subselect in a filter
but here is a logic for the filter if someone would come up with the same problem
tablename.NNNN_PROOF_DT = (SELECT MAX(X.NNNN_PROOF_DT) FROM tablename X WHERE tablename.NNNN_CLAIM_NUMBER = X.NNNN_CLAIM_NUMBER AND tablename.NNNN_LINE_CD = X.NNNN_LINE_CD)
please let me know if you have any questions.
sorry I am new to this so please do not take any offense -
We use the following statement where BUDAT is one of the fields in our custom table ztab:
Select MAX(BUDAT) from ztab (custom table) where...
When activating the above code, get the following error:
"Unknown column name "MAX(BUDAT)". not determined until runtime, you cannot specify a field list."
How to resolve this problem to get a max value of the field BUDAT in custom table ztab (it's not an internal table)?
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 10, 2008 3:56 PMHI,
Tyr having a space after and before BUDAT.
( BUDAT ).
Hope it helps,
Shreekant -
Who to select max total marks of a student from a stu_marks tale;
how to select max total marks from a student tab
Posted: Feb 1, 2007 5:25 AM Reply
SQL> select st_id max(sum(stu_marks))
2 from stu_marks;
select st_id max(sum(stu_marks))
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
thanksSQL> with t as (SELECT st_id,
2 sum(stu_marks) total_marks
3 FROM stu_marks
4 GROUP BY st_id)
5 select t.st_id, t.total_marks
6 from t
7 where t.total_marks = (select max(total_marks)
8 from t)
9 /
ST_ID TOTAL_MARKS
2 210
1 row selected.
SQL>Cheers
Sarma. -
How to select max total marks from a student tab
SQL> select st_id max(sum(stu_marks))
2 from stu_marks;
select st_id max(sum(stu_marks))
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
thanksselect st_id,sum(stu_marks) Marks
from stu_marks
group by st_id
but if you just want the highest mark try:
select st_id,sum(stu_marks) marks
from students
group by st_id
having sum(st_marks) =
( select max(sum(st_marks)) from students group by st_id) -
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
Maybe you are looking for
-
"ink system failure" error with code oxc19e0023 on a HP Photosmart Premium All-in-One Printer - C309
"ink system failure" error with code oxc19e0023 on have a HP Photosmart Premium All-in-One Printer - C309g - Have done all the resets and reseated the ink also tried replacing ink with new HP carts..getting frustrated please help This question was s
-
DBLookup with UCCE 7.5 & SQL 2005
Does anyone know if the DBLookup to a SQL2005 database is now supported on UCCE 7.5? This wasn't previously supported in earlier UCCE versions although there was a workaround, albeit unsupported. I can find zero documentation on this compatability in
-
VERY URGENT......PLS HELP
I am trying to develop a FTP client application which can talk with any FTP Server. When i am uploading a file using my client application,while the uploading process is going on,the file is being uploaded towards the server(the file size is graduall
-
How to test if particular character is empty in a row
Hi All , Requirement : To split the input file into two files . If the length of the row is 93 characters and the condition is If characters from 28 to 32 are empty then create a file with the name PCO1 .txt else create a file with the name PCO2 .txt
-
I need to deinstall adobe reader and then reinstall it.
I am having trouble using Adobe Reader and need to deintstall it and then reinstall it. Elana H HaLL